本文整理匯總了Java中com.rabbitmq.client.Channel.addShutdownListener方法的典型用法代碼示例。如果您正苦於以下問題:Java Channel.addShutdownListener方法的具體用法?Java Channel.addShutdownListener怎麽用?Java Channel.addShutdownListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.rabbitmq.client.Channel
的用法示例。
在下文中一共展示了Channel.addShutdownListener方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: send
import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
/****
* This method is used to publish the message to RabbitMQ
* @param routingKey
* @param msg is Eiffel Event
* @throws IOException
*/
public void send(String routingKey, String msg) throws IOException {
Channel channel = giveMeRandomChannel();
channel.addShutdownListener(new ShutdownListener() {
public void shutdownCompleted(ShutdownSignalException cause) {
// Beware that proper synchronization is needed here
if (cause.isInitiatedByApplication()) {
log.debug("Shutdown is initiated by application. Ignoring it.");
} else {
log.error("Shutdown is NOT initiated by application.");
log.error(cause.getMessage());
boolean cliMode = Boolean.getBoolean(PropertiesConfig.CLI_MODE);
if (cliMode) {
System.exit(-3);
}
}
}
});
BasicProperties msgProps = MessageProperties.BASIC;
if (usePersitance)
msgProps = MessageProperties.PERSISTENT_BASIC;
channel.basicPublish(exchangeName, routingKey, msgProps, msg.getBytes());
log.info("Published message with size {} bytes on exchange '{}' with routing key '{}'", msg.getBytes().length,
exchangeName, routingKey);
}