当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionFactory.setExceptionHandler方法代码示例

本文整理汇总了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");
    }
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:30,代码来源:RabbitMQApplicationCommunicator.java


注:本文中的com.rabbitmq.client.ConnectionFactory.setExceptionHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。