use of com.rabbitmq.client.AMQP.Queue.DeclareOk in project flux by eclipse.
the class RabbitMQMessageConnector method createInbox.
private String createInbox() throws IOException {
DeclareOk ok = this.channel.queueDeclare("", /*durable*/
false, /*exclusive*/
false, /*autoDelete*/
true, null);
final String inbox = ok.getQueue();
console.log("Inbox created: " + inbox);
channel.basicConsume(inbox, new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException {
try {
JSONObject obj = JSON.parse(body);
if (!isSelfOriginated(obj)) {
handleIncomingMessage(obj.getString("type"), obj.getJSONObject("data"));
}
} catch (Exception e) {
console.log(e);
}
}
/**
* Tests whether an incoming message originated from the same MessageConnector that
* is receiving it. (Such messages are skipped in keeping with how socketio does the same
* thing).
*/
private boolean isSelfOriginated(JSONObject obj) {
try {
String origin = obj.getString("origin");
return inbox.equals(origin);
} catch (Exception e) {
console.log(e);
}
return false;
}
});
return inbox;
}
use of com.rabbitmq.client.AMQP.Queue.DeclareOk in project camel by apache.
the class TemporaryQueueReplyManager method createListenerContainer.
@Override
protected Connection createListenerContainer() throws Exception {
log.debug("Creating connection");
Connection conn = endpoint.connect(executorService);
log.debug("Creating channel");
Channel channel = conn.createChannel();
// setup the basicQos
if (endpoint.isPrefetchEnabled()) {
channel.basicQos(endpoint.getPrefetchSize(), endpoint.getPrefetchCount(), endpoint.isPrefetchGlobal());
}
//Let the server pick a random name for us
DeclareOk result = channel.queueDeclare();
log.info("Using temporary queue name: {}", result.getQueue());
setReplyTo(result.getQueue());
//TODO check for the RabbitMQConstants.EXCHANGE_NAME header
channel.queueBind(getReplyTo(), endpoint.getExchangeName(), getReplyTo());
consumer = new RabbitConsumer(this, channel);
consumer.start();
return conn;
}
Aggregations