-
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 all 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 |
---|---|---|
|
@@ -138,28 +138,26 @@ protected boolean doReceive(Message<T> message) { | |
if (handler == null) { | ||
return false; | ||
} | ||
if (demand == 0L) { | ||
if (pending.size() < maxBufferedMessages) { | ||
pending.add(message); | ||
if (pending.size() < maxBufferedMessages) { | ||
pending.add(message); | ||
if (demand == 0) { | ||
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 (demand != Long.MAX_VALUE) { | ||
demand--; | ||
} | ||
} | ||
return true; | ||
} else { | ||
if (pending.size() > 0) { | ||
pending.add(message); | ||
message = pending.poll(); | ||
theHandler = handler; | ||
} | ||
if (demand != Long.MAX_VALUE) { | ||
demand--; | ||
} else { | ||
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; | ||
return false; | ||
} | ||
} | ||
deliver(theHandler, message); | ||
|
@@ -171,7 +169,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 +181,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.execute(__ -> { | ||
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. here we do execute the resume/fetch from the context thread so we do not have situations when we call resume and the same time we do receive a msg and we get 2msgs (on on the context thread and one on eventloop thread) |
||
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 was also not 100% right, when we do discard msg we should return with false to have that in the metrics