use of com.rabbitmq.client.AMQP.Exchange.DeclareOk in project jeesuite-libs by vakinge.
the class RabbitmqConsumerAdapter method start.
@Override
public void start() throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("");
factory.setPort(101);
factory.setUsername("");
factory.setPassword("");
Connection connect = factory.newConnection();
Channel channel = connect.createChannel();
// 声明exchange
DeclareOk declareOk = channel.exchangeDeclare("my.fanout3", "fanout", true);
channel.exchangeDeclare("test", "fanout");
String queueName = channel.queueDeclare().getQueue();
channel.queueBind(queueName, "test", "");
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
String message = new String(delivery.getBody(), "UTF-8");
System.out.println(" [x] Received '" + message + "'");
};
channel.basicConsume(queueName, true, deliverCallback, consumerTag -> {
});
}
use of com.rabbitmq.client.AMQP.Exchange.DeclareOk in project Insights by CognizantOneDevOps.
the class EngineTestData method publishMessage.
public static void publishMessage(String queueName, String routingKey, String playload) throws InsightsCustomException {
String exchangeName = ApplicationConfigProvider.getInstance().getAgentDetails().getAgentExchange();
Connection connection = null;
Channel channel = null;
try {
connection = RabbitMQConnectionProvider.getConnection();
channel = connection.createChannel();
} catch (IOException e) {
log.error(e);
}
String message = new GsonBuilder().disableHtmlEscaping().create().toJson(playload);
message = message.substring(1, message.length() - 1).replace("\\", "");
try {
DeclareOk exchangeResp = channel.exchangeDeclarePassive(exchangeName);
channel.queueDeclare(queueName, true, false, false, RabbitMQConnectionProvider.getQueueArguments());
channel.queueBind(queueName, exchangeName, routingKey);
channel.basicPublish(exchangeName, routingKey, null, message.getBytes());
// connection.close();
} catch (IOException e) {
try {
channel.exchangeDeclare(exchangeName, MQMessageConstants.EXCHANGE_TYPE);
channel.queueDeclare(queueName, true, false, false, RabbitMQConnectionProvider.getQueueArguments());
channel.queueBind(queueName, exchangeName, routingKey);
channel.basicPublish(exchangeName, routingKey, null, message.getBytes());
// connection.close();
} catch (IOException e1) {
log.error(e1);
}
}
}
use of com.rabbitmq.client.AMQP.Exchange.DeclareOk in project jeesuite-libs by vakinge.
the class RabbitmqConsumerAdapter method start.
@Override
public void start() throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("");
factory.setPort(101);
factory.setUsername("");
factory.setPassword("");
Connection connect = factory.newConnection();
Channel channel = connect.createChannel();
// 声明exchange
DeclareOk declareOk = channel.exchangeDeclare("my.fanout3", "fanout", true);
channel.exchangeDeclare("test", "fanout");
String queueName = channel.queueDeclare().getQueue();
channel.queueBind(queueName, "test", "");
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
String message = new String(delivery.getBody(), "UTF-8");
System.out.println(" [x] Received '" + message + "'");
};
channel.basicConsume(queueName, true, deliverCallback, consumerTag -> {
});
}
use of com.rabbitmq.client.AMQP.Exchange.DeclareOk in project Insights by CognizantOneDevOps.
the class WebhookEngineTestData method publishMessage.
@SuppressWarnings("unused")
public void publishMessage(String queueName, String routingKey, String playload) throws IOException, TimeoutException, InsightsCustomException {
String exchangeName = ApplicationConfigProvider.getInstance().getAgentDetails().getAgentExchange();
Connection connection = null;
Channel channel = null;
connection = RabbitMQConnectionProvider.getConnection();
channel = connection.createChannel();
String message = new GsonBuilder().disableHtmlEscaping().create().toJson(playload);
message = message.substring(1, message.length() - 1).replace("\\", "");
DeclareOk exchangeResp;
try {
exchangeResp = channel.exchangeDeclarePassive(exchangeName);
channel.queueDeclare(queueName, true, false, false, RabbitMQConnectionProvider.getQueueArguments());
channel.queueBind(queueName, exchangeName, routingKey);
channel.basicPublish(exchangeName, routingKey, null, message.getBytes());
// connection.close();
} catch (IOException e) {
try {
channel.exchangeDeclare(exchangeName, MQMessageConstants.EXCHANGE_TYPE);
channel.queueDeclare(queueName, true, false, false, RabbitMQConnectionProvider.getQueueArguments());
channel.queueBind(queueName, exchangeName, routingKey);
channel.basicPublish(exchangeName, routingKey, null, message.getBytes());
// connection.close();
} catch (IOException e1) {
LOG.error(e1);
}
}
}
Aggregations