Cannot connect to RabbitMQ existing queue using Java JMS API

359 views
Skip to first unread message

Dinnu's Channel

unread,
Feb 3, 2023, 9:15:30 AM2/3/23
to rabbitmq-users

I wanted to connect to RabbitMQ existing queue using Java JMS API. But I am getting below exception when I am trying to connect it.

Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'x-dead-letter-exchange' for queue 'TestDLXQueue2' in vhost '/': received none but current is the value 'TestDLExchnage' of type 'longstr', class-id=50, method-id=10)

RMQConnectionFactory connFactory = new RMQConnectionFactory(); 
Connection connection = connFactory.createConnection(); 
connection.start(); 
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destQueue = session.createQueue("TestDLXQueue2");

If I remove the Queue and run the above snippet it worked but I have to pass the "x-dead-letter-exchange" argument in the RabbitMQ queue but I did not find a method to pass in from the JMS API.

Can anyone help me to resolve this issue without deleting the Queue?

I have tried removing the Queue and ran the above snippet it worked, Now I want to connect to the existing RabbitMQ Queue which is configured with "x-dead-letter-exchange" policy.

Arnaud Cogoluègnes

unread,
Feb 6, 2023, 3:34:53 AM2/6/23
to rabbitmq-users
You can cast the Session to RMQSession and use the setQueueDeclareArguments(Map) method to set the arguments the session will use to declare the queue.

An alternative is not calling the Session#createQueue(String) and creating an RMQDestination instance. One constructor allows setting the queue arguments.

In both cases, you're coupling the application code to the JMS implementation so you should keep this code as isolated as possible, not scattered in the application code.

Dinesh Pega

unread,
Feb 8, 2023, 12:51:58 PM2/8/23
to rabbitm...@googlegroups.com
Hi Arnaud Cogoluègnes, Thank you so much for your response.
Here we have implemented our tool to only support JMS 1.1 specification and it is supported for all other messaging brokers like ActiveMQ, IBM MQ by configuring their supported jar files.
So we cannot modify the code, Do we have any other option from the configuration level to change to fix this issue?

Thanks in advance.

--
You received this message because you are subscribed to a topic in the Google Groups "rabbitmq-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rabbitmq-users/-7pLY4iZQvI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rabbitmq-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rabbitmq-users/60683539-d52e-4a64-bca4-133858f953f2n%40googlegroups.com.

Arnaud Cogoluègnes

unread,
Feb 9, 2023, 3:05:38 AM2/9/23
to rabbitmq-users
I don't know how your application is configured. If you're using JNDI and RMQObjectFactory you should be able to set the queueDeclareArguments property for this destination. This way the application code would be decoupled from the destination definition.
Reply all
Reply to author
Forward
0 new messages