use of com.rabbitmq.client.DeliverCallback in project rabbitmq-tutorials by rabbitmq.
the class Recv method main.
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
String message = new String(delivery.getBody(), StandardCharsets.UTF_8);
System.out.println(" [x] Received '" + message + "'");
};
channel.basicConsume(QUEUE_NAME, true, deliverCallback, consumerTag -> {
});
}
use of com.rabbitmq.client.DeliverCallback 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.DeliverCallback in project egeria-connector-sas-viya by odpi.
the class RepositoryEventMapper method start.
/**
* {@inheritDoc}
*/
@Override
public void start() throws ConnectorCheckedException {
super.start();
final String methodName = "start";
auditLog.logMessage(methodName, AuditCode.EVENT_MAPPER_STARTING.getMessageDefinition());
if (!(repositoryConnector instanceof RepositoryConnector)) {
raiseConnectorCheckedException(ErrorCode.EVENT_MAPPER_IMPROPERLY_INITIALIZED, methodName, null, repositoryConnector.getServerName());
}
this.catalogOMRSRepositoryConnector = (RepositoryConnector) this.repositoryConnector;
try {
this.catalogOMRSMetadataCollection = (MetadataCollection) catalogOMRSRepositoryConnector.getMetadataCollection();
} catch (RepositoryErrorException e) {
raiseConnectorCheckedException(ErrorCode.REST_CLIENT_FAILURE, methodName, e, catalogOMRSRepositoryConnector.getServerName());
}
this.typeDefStore = catalogOMRSMetadataCollection.getTypeDefStore();
catalogOMRSMetadataCollection.setEventMapper(this);
this.metadataCollectionId = catalogOMRSRepositoryConnector.getMetadataCollectionId();
this.originatorServerName = catalogOMRSRepositoryConnector.getServerName();
this.originatorServerType = catalogOMRSRepositoryConnector.getServerType();
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
String message = new String(delivery.getBody(), "UTF-8");
log.debug("SAS Catalog Event received: '{}':'{}'", delivery.getEnvelope().getRoutingKey(), message);
try {
Event<CatalogEventPayload> event = this.mapper.readValue(message, Event.class);
String eventPayload = event.getPayloadAsString();
try {
processEvent(eventPayload);
} catch (Exception e) {
log.error("Could not process event payload.", e);
return;
}
} catch (IOException e) {
log.warn("Could not parse event payload. Reason: {}", e.getLocalizedMessage());
return;
}
};
try {
channel.basicConsume(queueName, true, deliverCallback, consumerTag -> {
});
} catch (Exception e) {
log.error("RabbitMQ basic consumer failed to start", e);
}
}
use of com.rabbitmq.client.DeliverCallback in project amos2022ss02-audit-chain by amosproj.
the class AggregateConsumerClient method start.
public void start() throws IOException, TimeoutException {
System.out.println("Starting to receive Messages.");
Connection connection = this.factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
AggregateMessage message;
try {
message = (AggregateMessage) deserializeMessage(delivery.getBody());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
Vector<Message> messages = message.getMessages();
for (int i = 0; i < message.getMessageSize(); i++) {
Message single_message = messages.get(i);
this.persistenceStrategy.StoreMessage(new JsonMessage(single_message.getSequence_number(), single_message.getMessage()));
System.out.println(String.format("Received event %d with the content: %s", single_message.getSequence_number(), single_message.getMessage()));
}
};
channel.basicConsume(QUEUE_NAME, true, deliverCallback, consumerTag -> {
});
}
use of com.rabbitmq.client.DeliverCallback in project rabbitmq-tutorials by rabbitmq.
the class ReceiveLogs method main.
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
String queueName = channel.queueDeclare().getQueue();
channel.queueBind(queueName, EXCHANGE_NAME, "");
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 -> {
});
}
Aggregations