-
Notifications
You must be signed in to change notification settings - Fork 10
Need an interface like createConsumer(String exchange, String queue, String routingKey) #15
Comments
@kolyneh The rxrabbit consumer does not create any queues or bindings per design. So if you need to set up any state on the broker (apart from channels and connections) you can either use the vanilla amqp-client interfaces or use the https://github.com/meltwater/rxrabbit/blob/master/rxrabbit/src/main/java/com/meltwater/rxrabbit/AdminChannel.java (which you get by calling https://github.com/meltwater/rxrabbit/blob/581ddb8bc7afaa4a8d7b6efb25c82b87fff5a692/rxrabbit/src/main/java/com/meltwater/rxrabbit/impl/DefaultChannelFactory.java#L90) And then using that AdminChannel to
After you have done these three calls an exchange a queue and a binding is either created or already present on the rabbit broker. Then you can just start consuming from the queue like: createConsumeChannel() |
If you just want a temporary/ad hoc queue, that is destroyed after disconnect you can use the createConsumeChannel(String exchange, String routingkey) method. For an example see: https://github.com/meltwater/rxrabbit/blob/581ddb8bc7afaa4a8d7b6efb25c82b87fff5a692/rxrabbit/src/test/java/com/meltwater/rxrabbit/RxRabbitTests.java#L206 |
If these two scenarios does not cover your use case I need more information on what you are trying to achieve @kolyneh |
@karlney Sorry for this late reply but thanks a lot! I'm use rxrabbit on Android. Every thing is ok, Log: It's occur at this:
How to deal with this? |
@kolyneh I think the key is the OnErrorNotImplementedException part. What you should do is that when you get an error in your RxJava flow you need to start the re-connect loop, so that whenever you get another available connection (i.e switching over from WiFi to 4G network) then you re-connect to the broker using the new connection. In the existing code that is handled in https://github.com/meltwater/rxrabbit/blob/581ddb8bc7afaa4a8d7b6efb25c82b87fff5a692/rxrabbit/src/main/java/com/meltwater/rxrabbit/impl/SingleChannelConsumer.java#L119 with the implementation in Without knowing how the new 2.x code you have now I don't think I can help you further. TL;DR you have forgotten about error handling in one or more places - and the error handling is done by dropping the existing connections and consumers, and re-create them again when a new NW connection is established. |
@karlney Seems there is only a BackoffAlgorithm interface that we can use to change the backoff behavior out of the box, right? I found there is some param we can config in the origin rabbit codes: It works on my old project. |
Yes you can implement your own BackoffAlgorithm. Regarding the underlying connection factory settings - they might work but we found that they were unreliable in some cases - but they might work in your case so please go ahead and try them. You might have to change some code in the rx-rabbit ConnectionFactory to be able to set them - but it should not be difficult. |
@karlney I have implement my BackoffAlgorithm like:
When network is available, delay is set to 5000, if not is set to -1. And modify ConnectionRetryHandler like:
Only added this code: And run create connection when network is reconnect . It works. But when publishing message, it crash , log:
Where the code is : It's cause by this code in my BackoffAlgorithm : I add this code because getDelayMs will call before i receive network change event. How to handle this? |
@kolyneh did you sort this out yourself. Otherwise I would just use:
The reason is that its a race condition to first do an if statement, and then act like the if argument is also true inside the if body in the absence if any locking mechanism. |
We need an interface like createConsumer(String exchange, String queue, String routingKey) to specify queue rather than a server-named one.
If not , is there any solution to create a cousumer with specified exchang, queue and routingKey?
The text was updated successfully, but these errors were encountered: