use of de.gessnerfl.rabbitmq.queue.management.connection.CloseableChannelWrapper in project rabbitmq-queue-management by gessnerfl.
the class RabbitMqTestEnvironment method setup.
public void setup() {
try (CloseableChannelWrapper wrapper = connector.connectAsClosable(BROKER)) {
Channel channel = wrapper.getChannel();
declareExchanges(channel);
declareQueues(channel);
} catch (RabbitMqEnvironmentException e) {
cleanup();
throw e;
}
}
use of de.gessnerfl.rabbitmq.queue.management.connection.CloseableChannelWrapper in project rabbitmq-queue-management by gessnerfl.
the class RabbitMqTestEnvironment method cleanup.
public void cleanup() {
try (CloseableChannelWrapper wrapper = connector.connectAsClosable(BROKER)) {
Channel channel = wrapper.getChannel();
deleteQueues(channel);
deleteExchanges(channel);
}
}
use of de.gessnerfl.rabbitmq.queue.management.connection.CloseableChannelWrapper in project rabbitmq-queue-management by gessnerfl.
the class RabbitMqTestEnvironment method publishMessage.
public void publishMessage(String exchange, String routingKey) {
try (CloseableChannelWrapper wrapper = connector.connectAsClosable(BROKER)) {
Channel channel = wrapper.getChannel();
publishMessage(channel, exchange, routingKey, 1);
}
}
use of de.gessnerfl.rabbitmq.queue.management.connection.CloseableChannelWrapper in project rabbitmq-queue-management by gessnerfl.
the class QueueListOperation method getMessagesFromQueue.
public List<Message> getMessagesFromQueue(String brokerName, String queueName, int maxNumberOfMessages) {
try (CloseableChannelWrapper wrapper = connector.connectAsClosable(brokerName)) {
List<Message> messages = new ArrayList<>();
Channel channel = wrapper.getChannel();
channel.basicQos(DEFAULT_FETCH_COUNT);
int fetched = 0;
boolean messagesAvailable = true;
Long lastDeliveryTag = null;
while (fetched < maxNumberOfMessages && messagesAvailable) {
GetResponse response = channel.basicGet(queueName, false);
if (response != null) {
messages.add(createMessage(response));
lastDeliveryTag = response.getEnvelope().getDeliveryTag();
fetched++;
messagesAvailable = response.getMessageCount() > 0;
} else {
messagesAvailable = false;
}
}
if (lastDeliveryTag != null) {
channel.basicNack(lastDeliveryTag, true, true);
}
return messages;
} catch (IOException e) {
throw new MessageFetchFailedException(e);
}
}
use of de.gessnerfl.rabbitmq.queue.management.connection.CloseableChannelWrapper in project rabbitmq-queue-management by gessnerfl.
the class MessageOperationExecutor method consumeMessageApplyFunctionAndAckknowlegeOnSuccess.
public void consumeMessageApplyFunctionAndAckknowlegeOnSuccess(String brokerName, String queueName, String expectedChecksum, MessageOperationFunction fn) {
try (CloseableChannelWrapper wrapper = connector.connectAsClosable(brokerName)) {
Channel channel = wrapper.getChannel();
GetResponse response = getFirstMessage(queueName, channel);
String checksum = messageChecksum.createFor(response.getProps(), response.getBody());
if (checksum.equals(expectedChecksum)) {
fn.apply(channel, response);
channel.basicAck(response.getEnvelope().getDeliveryTag(), false);
} else {
channel.basicNack(response.getEnvelope().getDeliveryTag(), false, true);
throw new MessageOperationFailedException("Checksum does not match");
}
} catch (Exception e) {
if (e instanceof MessageOperationFailedException) {
throw (MessageOperationFailedException) e;
}
throw new MessageOperationFailedException(e);
}
}
Aggregations