本文整理汇总了Java中com.rabbitmq.client.ConnectionFactory.setExceptionHandler方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionFactory.setExceptionHandler方法的具体用法?Java ConnectionFactory.setExceptionHandler怎么用?Java ConnectionFactory.setExceptionHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rabbitmq.client.ConnectionFactory
的用法示例。
在下文中一共展示了ConnectionFactory.setExceptionHandler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
@Override
public void init(AbstractConfiguration config, ApplicationListenerFactory factory) {
try {
ConnectionFactory cf = new ConnectionFactory();
cf.setUsername(config.getString("rabbitmq.userName", ConnectionFactory.DEFAULT_USER));
cf.setPassword(config.getString("rabbitmq.password", ConnectionFactory.DEFAULT_PASS));
cf.setVirtualHost(config.getString("rabbitmq.virtualHost", ConnectionFactory.DEFAULT_VHOST));
cf.setAutomaticRecoveryEnabled(true);
cf.setExceptionHandler(new RabbitMQExceptionHandler());
this.conn = cf.newConnection(Address.parseAddresses(config.getString("rabbitmq.addresses")));
this.channel = conn.createChannel();
logger.trace("Initializing RabbitMQ application resources ...");
APPLICATION_TOPIC = config.getString("communicator.application.topic");
this.channel.exchangeDeclare(APPLICATION_TOPIC, "topic", true);
logger.trace("Initializing RabbitMQ application consumer's workers ...");
Channel consumerChan = this.conn.createChannel();
consumerChan.queueDeclare(config.getString("rabbitmq.app.queueName"), true, false, true, null);
consumerChan.queueBind(config.getString("rabbitmq.app.queueName"), APPLICATION_TOPIC, config.getString("rabbitmq.app.routingKey"));
consumerChan.basicConsume(config.getString("rabbitmq.app.queueName"), true, new RabbitMQApplicationConsumer(consumerChan, factory.newListener()));
} catch (IOException | TimeoutException e) {
logger.error("Failed to connect to RabbitMQ servers", e);
throw new IllegalStateException("Init RabbitMQ communicator failed");
}
}