本文整理汇总了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);
}