Skip to content

Commit d8628ae

Browse files
authored
Update API.java
1 parent cd27027 commit d8628ae

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/isc/rabbitmq/API.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ public API(String host, int port, String user, String pass, String virtualHost,
3636
_connection = factory.newConnection();
3737
_channel = _connection.createChannel();
3838
try {
39-
// Check that queue exists
40-
// Method throws exception if queue does not exist or is exclusive
41-
// Correct exception text: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'queue'
42-
com.rabbitmq.client.AMQP.Queue.DeclareOk declareOk = _channel.queueDeclarePassive(queue);
39+
// Do we need to declare queue?
40+
// No if we're sending by exchange/routing_key
41+
if (exchange != null && !exchange.isEmpty()) {
42+
// Check that queue exists
43+
// Method throws exception if queue does not exist or is exclusive
44+
// Correct exception text: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'queue'
45+
com.rabbitmq.client.AMQP.Queue.DeclareOk declareOk = _channel.queueDeclarePassive(queue);
46+
}
4347
} catch (java.io.IOException ex) {
4448
// Exception closes the channel.
4549
// So we need to create new one.

0 commit comments

Comments
 (0)