Skip to content

Use the same context to guarantee message delivery order #52

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

Merged
merged 7 commits into from
Feb 1, 2018

Conversation

Sammers21
Copy link
Contributor

A solution for #51.

@Sammers21
Copy link
Contributor Author

Sammers21 commented Jan 29, 2018

@vietj, can you review the changes?

@vietj
Copy link
Contributor

vietj commented Jan 29, 2018

we need to come up with a test for this

@vietj
Copy link
Contributor

vietj commented Jan 31, 2018

any test for this ?

@Sammers21
Copy link
Contributor Author

@vietj, sure, I will work on it

…e_order

# Conflicts:
#	src/test/java/io/vertx/rabbitmq/RabbitMQServiceTest.java
@Sammers21
Copy link
Contributor Author

@vietj , just done

@vietj
Copy link
Contributor

vietj commented Feb 1, 2018

what is the actual thread if we remove run on context ?

@vietj
Copy link
Contributor

vietj commented Feb 1, 2018

the solution appears faulty to me because we should be on the vertx thread and the correct solution would rather be to capture somewhere the context and use context#runOnContext rather than vertx.runOnContext

@vietj
Copy link
Contributor

vietj commented Feb 1, 2018

So ConsumerHandler should capture the current context when it is created and then it shall be used, the test should check that we are on a still on a Vert.x thread and the same than the one that called the basicConsume method

@Sammers21
Copy link
Contributor Author

@vietj, can we catch a context in the ConsumerHandler constructor by calling vertx#getOrCreateContext and then use context#runOnContext for handling?

}));

awaitLatch(latch);
testComplete();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testComplete should not be called here, it is only necessary when called asynchronously and if you call await() in the junit thread

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

assertNotNull(json);
String body = json.getString("body");
assertNotNull(body);
log.info("received: " + body + " expected: " + expectedMessage);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to log

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

channel.basicPublish("", queueName, properties, msg.getBytes("UTF-8"));

vertx.eventBus().consumer(address, msg -> {
String expectedMessage = receiveOrderQueue.poll();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather collect all messages in a synchronized list, remove the latch and use assertWaitUntil(() -> list.size() == 1000) in the main thread, it will be more clear and easier to read

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and check the message order in the junit thread after assertWaitUntil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

AMQP.BasicProperties properties = new AMQP.BasicProperties.Builder().contentType("text/plain").contentEncoding("UTF-8").build();

// send messages
for (String msg : sendingOrder)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should likely publish messages after having etup the event bus consumer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is very important to have unconsumed messages in rabbitmq before running a consumer, that is how the problem were discovered. The order might looks like fine when publishing and instantly receiving because of delay between arrived messages.

That is what @tibor-kocsis saying about issue reproducing:

If you run the Sender, then a few minutes later the Receiver, the output will be the following

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok, are we sure then this is enough ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is enough

@vietj
Copy link
Contributor

vietj commented Feb 1, 2018

looks ok now

@vietj vietj merged commit e94e8dc into vert-x3:master Feb 1, 2018
@vietj vietj removed the to review label Feb 1, 2018
@vietj vietj changed the title Remove runOnContext and use plain code instead Use the same context to guarantee message delivery order Feb 1, 2018
@vietj vietj added this to the 3.5.1 milestone Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants