Example usage for com.rabbitmq.client Channel basicPublish

List of usage examples for com.rabbitmq.client Channel basicPublish

Introduction

In this page you can find the example usage for com.rabbitmq.client Channel basicPublish.

Prototype

void basicPublish(String exchange, String routingKey, boolean mandatory, BasicProperties props, byte[] body)
        throws IOException;

Source Link

Document

Publish a message.

Usage

From source file:org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.java

License:Apache License

/**
 * Send the given response message to the given destination.
 * @param channel the Rabbit channel to operate on
 * @param replyTo the Rabbit ReplyTo string to use when sending. Currently interpreted to be the routing key.
 * @param message the Rabbit message to send
 * @throws Exception if thrown by Rabbit API methods
 * @see #postProcessResponse(Message, Message)
 *//*  w w w .j a  va2 s  .co m*/
protected void sendResponse(Channel channel, Address replyTo, Message message) throws Exception {
    postProcessChannel(channel, message);

    try {
        logger.debug("Publishing response to exchanage = [" + replyTo.getExchangeName() + "], routingKey = ["
                + replyTo.getRoutingKey() + "]");
        channel.basicPublish(replyTo.getExchangeName(), replyTo.getRoutingKey(), this.mandatoryPublish,
                this.messagePropertiesConverter.fromMessageProperties(message.getMessageProperties(), encoding),
                message.getBody());
    } catch (Exception ex) {
        throw RabbitExceptionTranslator.convertRabbitAccessException(ex);
    }
}