-
Notifications
You must be signed in to change notification settings - Fork 2.1k
make sure after resume we just deliver one message at one moment #5525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.x
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,36 +133,24 @@ public synchronized Future<Void> unregister() { | |
} | ||
|
||
protected boolean doReceive(Message<T> message) { | ||
Handler<Message<T>> theHandler; | ||
synchronized (this) { | ||
if (handler == null) { | ||
return false; | ||
} | ||
if (demand == 0L) { | ||
if (pending.size() < maxBufferedMessages) { | ||
pending.add(message); | ||
return true; | ||
} else { | ||
discard(message); | ||
if (discardHandler != null) { | ||
discardHandler.handle(message); | ||
} else { | ||
log.warn("Discarding message as more than " + maxBufferedMessages + " buffered in paused consumer. address: " + address); | ||
} | ||
} | ||
if (pending.size() < maxBufferedMessages) { | ||
pending.add(message); | ||
checkNextTick(); | ||
return true; | ||
} else { | ||
if (pending.size() > 0) { | ||
pending.add(message); | ||
message = pending.poll(); | ||
} | ||
if (demand != Long.MAX_VALUE) { | ||
demand--; | ||
discard(message); | ||
if (discardHandler != null) { | ||
discardHandler.handle(message); | ||
} else { | ||
String pause = demand == 0 ? "paused" : "NOT paused"; | ||
log.warn("Discarding message as more than " + maxBufferedMessages + " buffered in " + pause + " consumer. address: " + address); | ||
} | ||
theHandler = handler; | ||
} | ||
} | ||
deliver(theHandler, message); | ||
return true; | ||
} | ||
|
||
|
@@ -171,7 +159,7 @@ protected void dispatch(Message<T> msg, ContextInternal context, Handler<Message | |
if (handler == null) { | ||
throw new NullPointerException(); | ||
} | ||
context.emit(msg, handler); | ||
context.dispatch(msg, handler); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was reverted as it had a side effect: |
||
} | ||
|
||
private void deliver(Handler<Message<T>> theHandler, Message<T> message) { | ||
|
@@ -183,8 +171,8 @@ private void deliver(Handler<Message<T>> theHandler, Message<T> message) { | |
|
||
private synchronized void checkNextTick() { | ||
// Check if there are more pending messages in the queue that can be processed next time around | ||
if (!pending.isEmpty() && demand > 0L) { | ||
context.nettyEventLoop().execute(() -> { | ||
if (demand > 0L && !pending.isEmpty()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I flip here so the demand evaulated first |
||
context.emit(__ -> { | ||
Message<T> message; | ||
Handler<Message<T>> theHandler; | ||
synchronized (MessageConsumerImpl.this) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1401,7 +1401,6 @@ public void testUnregisterConsumerDiscardPendingMessages() { | |
eb.send(ADDRESS1, "val1"); | ||
Context ctx = Vertx.currentContext(); | ||
ctx.runOnContext(v -> { | ||
consumer.resume(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was in the past executed on eventloop thread on the context... now this is executed on the context thread (in case we area lready on it it will not schedule new job, in case we are on another thread it will schedule an async job. |
||
((MessageConsumerImpl<?>) consumer).discardHandler(discarded -> { | ||
assertEquals("val1", discarded.body()); | ||
testComplete(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method simplified a lot and here we always just put it in hte pending (if the buffer not full yet of course) and send a tick (that will decied if we need to do anything right now or not)
as the tick evaulation happen on the contex thread we are safe (single threaded)