private String getVersion() { return this.rabbitTemplate.execute((channel) -> channel.getConnection() .getServerProperties().get("version").toString()); }
@Test public void testInbound() { @SuppressWarnings("unchecked") final Message<String> out = (Message<String>) new ObjectToJsonTransformer() .transform(new GenericMessage<Foo>(new Foo())); MessageProperties messageProperties = new MessageProperties(); DefaultAmqpHeaderMapper.outboundMapper().fromHeadersToRequest(out.getHeaders(), messageProperties); final BasicProperties props = new DefaultMessagePropertiesConverter().fromMessageProperties(messageProperties, "UTF-8"); this.rabbitTemplate.execute(channel -> { channel.basicPublish("", JSON_TESTQ, props, out.getPayload().getBytes()); return null; }); Object received = this.rabbitTemplate.receiveAndConvert(JSON_TESTQ); assertThat(received, instanceOf(Foo.class)); }
@Override @Nullable public <T> T execute(ChannelCallback<T> action) { return execute(action, getConnectionFactory()); }
@Override @Nullable public <T> T execute(ChannelCallback<T> action) { return execute(action, getConnectionFactory()); }
@Nullable protected Message doSendAndReceiveWithFixed(final String exchange, final String routingKey, final Message message, final CorrelationData correlationData) { Assert.state(this.isListener, () -> "RabbitTemplate is not configured as MessageListener - " + "cannot use a 'replyAddress': " + this.replyAddress); return execute(channel -> { return doSendAndReceiveAsListener(exchange, routingKey, message, correlationData, channel); }, obtainTargetConnectionFactory(this.sendConnectionFactorySelectorExpression, message)); }
@Nullable protected Message doSendAndReceiveWithFixed(final String exchange, final String routingKey, final Message message, final CorrelationData correlationData) { Assert.state(this.isListener, () -> "RabbitTemplate is not configured as MessageListener - " + "cannot use a 'replyAddress': " + this.replyAddress); return execute(channel -> { return doSendAndReceiveAsListener(exchange, routingKey, message, correlationData, channel); }, obtainTargetConnectionFactory(this.sendConnectionFactorySelectorExpression, message)); }
@Override public void declareExchange(final Exchange exchange) { try { this.rabbitTemplate.execute(channel -> { declareExchanges(channel, exchange); return null; }); } catch (AmqpException e) { logOrRethrowDeclarationException(exchange, "exchange", e); } }
@Override @ManagedOperation(description = "Delete a queue from the broker if unused and empty (when corresponding arguments are true") public void deleteQueue(final String queueName, final boolean unused, final boolean empty) { this.rabbitTemplate.execute(channel -> { channel.queueDelete(queueName, unused, empty); return null; }); }
@Override @ManagedOperation(description = "Delete a queue from the broker if unused and empty (when corresponding arguments are true") public void deleteQueue(final String queueName, final boolean unused, final boolean empty) { this.rabbitTemplate.execute(channel -> { channel.queueDelete(queueName, unused, empty); return null; }); }
@Override @ManagedOperation(description = "Purge a queue and return the number of messages purged") public int purgeQueue(final String queueName) { return this.rabbitTemplate.execute(channel -> { // NOSONAR never returns null PurgeOk queuePurged = channel.queuePurge(queueName); if (this.logger.isDebugEnabled()) { this.logger.debug("Purged queue: " + queueName + ", " + queuePurged); } return queuePurged.getMessageCount(); }); }
@Override public void declareExchange(final Exchange exchange) { try { this.rabbitTemplate.execute(channel -> { declareExchanges(channel, exchange); return null; }); } catch (AmqpException e) { logOrRethrowDeclarationException(exchange, "exchange", e); } }
@Override @ManagedOperation(description = "Purge a queue and return the number of messages purged") public int purgeQueue(final String queueName) { return this.rabbitTemplate.execute(channel -> { // NOSONAR never returns null PurgeOk queuePurged = channel.queuePurge(queueName); if (this.logger.isDebugEnabled()) { this.logger.debug("Purged queue: " + queueName + ", " + queuePurged); } return queuePurged.getMessageCount(); }); }
@Override public void send(final String exchange, final String routingKey, final Message message, @Nullable final CorrelationData correlationData) throws AmqpException { execute(channel -> { doSend(channel, exchange, routingKey, message, (RabbitTemplate.this.returnCallback != null || (correlationData != null && StringUtils.hasText(correlationData.getId()))) && RabbitTemplate.this.mandatoryExpression.getValue( RabbitTemplate.this.evaluationContext, message, Boolean.class), correlationData); return null; }, obtainTargetConnectionFactory(this.sendConnectionFactorySelectorExpression, message)); }
@Override @ManagedOperation(description = "Delete a queue from the broker") public boolean deleteQueue(final String queueName) { return this.rabbitTemplate.execute(channel -> { // NOSONAR never returns null try { channel.queueDelete(queueName); } catch (IOException e) { return false; } return true; }); }
@Override @ManagedOperation(description = "Delete a queue from the broker") public boolean deleteQueue(final String queueName) { return this.rabbitTemplate.execute(channel -> { // NOSONAR never returns null try { channel.queueDelete(queueName); } catch (IOException e) { return false; } return true; }); }
private <R, S> boolean doReceiveAndReply(final String queueName, final ReceiveAndReplyCallback<R, S> callback, final ReplyToAddressCallback<S> replyToAddressCallback) throws AmqpException { Boolean result = execute(channel -> { Message receiveMessage = receiveForReply(queueName, channel); if (receiveMessage != null) { return sendReply(callback, replyToAddressCallback, channel, receiveMessage); } return false; }, obtainTargetConnectionFactory(this.receiveConnectionFactorySelectorExpression, queueName)); return result == null ? false : result; }
private <R, S> boolean doReceiveAndReply(final String queueName, final ReceiveAndReplyCallback<R, S> callback, final ReplyToAddressCallback<S> replyToAddressCallback) throws AmqpException { Boolean result = execute(channel -> { Message receiveMessage = receiveForReply(queueName, channel); if (receiveMessage != null) { return sendReply(callback, replyToAddressCallback, channel, receiveMessage); } return false; }, obtainTargetConnectionFactory(this.receiveConnectionFactorySelectorExpression, queueName)); return result == null ? false : result; }
private Long determineMessageCount() { return this.templateWithConfirmsEnabled.execute(channel -> channel.messageCount(ROUTE)); }
@Override @ManagedOperation(description = "Declare a binding on the broker (this operation is not available remotely)") public void declareBinding(final Binding binding) { try { this.rabbitTemplate.execute(channel -> { declareBindings(channel, binding); return null; }); } catch (AmqpException e) { logOrRethrowDeclarationException(binding, "binding", e); } }
static void declareTestQueue(RabbitTemplate template, final String routingKey) { // declare and bind queue template.execute(channel -> { Queue.DeclareOk res = channel.queueDeclarePassive(TestConstants.QUEUE_NAME); String queueName = res.getQueue(); System .out .println("Queue Name = " + queueName); channel.queueBind(queueName, TestConstants.EXCHANGE_NAME, routingKey); return queueName; }); }