use of com.rabbitmq.client.AMQP.BasicProperties 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;
}
Aggregations