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


Java ShutdownListener类代码示例

本文整理汇总了Java中com.rabbitmq.client.ShutdownListener的典型用法代码示例。如果您正苦于以下问题:Java ShutdownListener类的具体用法?Java ShutdownListener怎么用?Java ShutdownListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ShutdownListener类属于com.rabbitmq.client包,在下文中一共展示了ShutdownListener类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initRabbitMQ

import com.rabbitmq.client.ShutdownListener; //导入依赖的package包/类
private void initRabbitMQ() throws IOException {
	Server.LOGGER.info("Initialization of the Notifications channel");
	mRabbitMQManager.getChannel().addShutdownListener(new ShutdownListener() {
		
		@Override
		public void shutdownCompleted(ShutdownSignalException cause) {
			cause.printStackTrace();
		}
	});
	mRabbitMQManager.getChannel().exchangeDeclare("Pub", BuiltinExchangeType.FANOUT, true);
	String queueName = mRabbitMQManager.getChannel().queueDeclare().getQueue();
	mRabbitMQManager.getChannel().queueBind(queueName, "Pub", "");
	
	mRabbitMQManager.getChannel().basicConsume(queueName, true, new RabbitMQConsumer(this, mRabbitMQManager.getChannel()));
	Server.LOGGER.info("Initialization of the Pub channel done.");
}
 
开发者ID:FightForSub,项目名称:FFS-PubSub,代码行数:17,代码来源:Server.java

示例2: send

import com.rabbitmq.client.ShutdownListener; //导入依赖的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);
}
 
开发者ID:Ericsson,项目名称:eiffel-remrem-publish,代码行数:34,代码来源:RabbitMqProperties.java

示例3: handleCommonMethods

import com.rabbitmq.client.ShutdownListener; //导入依赖的package包/类
/**
 * Handles common method invocations.
 */
boolean handleCommonMethods(Object delegate, Method method, Object[] args) throws Throwable {
  if ("abort".equals(method.getName()) || "close".equals(method.getName())) {
    try {
      Reflection.invoke(delegate, method, args);
      return true;
    } finally {
      closed = true;
      afterClosure();
      interruptWaiters();
    }
  } else if ("addShutdownListener".equals(method.getName()) && args[0] != null)
    shutdownListeners.add((ShutdownListener) args[0]);
  else if ("removeShutdownListener".equals(method.getName()) && args[0] != null)
    shutdownListeners.remove((ShutdownListener) args[0]);
  return false;
}
 
开发者ID:jhalterman,项目名称:lyra,代码行数:20,代码来源:RetryableResource.java

示例4: init

import com.rabbitmq.client.ShutdownListener; //导入依赖的package包/类
protected synchronized void init() throws RabbitMQTransportException
{
	try
	{
		channel.addShutdownListener(new ShutdownListener()
			{
				@Override
				public void shutdownCompleted(ShutdownSignalException cause)
				{
					disconnect(cause.getMessage());
				}
			});

		channel.exchangeDeclare(
				exchange.getName(),
				exchange.getType().toString(),
				exchange.isDurable(),
				exchange.isAutoDelete(),
				null
			);
	}
	catch (IOException e)
	{
		String msg = LOGGER.translate("EXCHANGE_CREATE_ERROR", e.getMessage());
		LOGGER.error(msg, e);
		throw new RabbitMQTransportException(msg);
	}
}
 
开发者ID:Esri,项目名称:rabbitmq-for-geoevent,代码行数:29,代码来源:RabbitMQComponentBase.java

示例5: connect

import com.rabbitmq.client.ShutdownListener; //导入依赖的package包/类
private void connect() throws AiravataException {
    try {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setUri(properties.getBrokerUrl());
        connectionFactory.setAutomaticRecoveryEnabled(properties.isAutoRecoveryEnable());
        connection = connectionFactory.newConnection();
        connection.addShutdownListener(new ShutdownListener() {
            public void shutdownCompleted(ShutdownSignalException cause) {
            }
        });
        log.info("connected to rabbitmq: " + connection + " for " + properties.getExchangeName());
        channel = connection.createChannel();
        if (properties.getPrefetchCount() > 0) {
            channel.basicQos(properties.getPrefetchCount());
        }

        if (properties.getExchangeName() != null) {
            channel.exchangeDeclare(properties.getExchangeName(),
                                    properties.getExchangeType(),
                                    true); //durable
        }
    } catch (Exception e) {
        String msg = "RabbitMQ connection issue for exchange : " + properties.getExchangeName();
        log.error(msg);
        throw new AiravataException(msg, e);
    }


}
 
开发者ID:apache,项目名称:airavata,代码行数:30,代码来源:RabbitMQPublisher.java

示例6: addShutdownListener

import com.rabbitmq.client.ShutdownListener; //导入依赖的package包/类
private void addShutdownListener() {
    connection.addShutdownListener(new ShutdownListener() {
        public void shutdownCompleted(ShutdownSignalException cause) {
            log.error("RabbitMQ connection " + connection + " for " + properties.getExchangeName() + " has been shut down", cause);
        }
    });
}
 
开发者ID:apache,项目名称:airavata,代码行数:8,代码来源:RabbitMQSubscriber.java

示例7: attachToQueue

import com.rabbitmq.client.ShutdownListener; //导入依赖的package包/类
private void attachToQueue(boolean recover) throws IOException {
    Connection cn = rabbitConnectionFactory.createConnection();
    this.channel = cn.createChannel(false);
    channel.exchangeDeclare(this.topicName(), "topic", true);
    this.queueName = channel.queueDeclare(
            this.topicName() + ".__." + this.queueName()
            , true, false, false, null).getQueue();
    if (recover) {
        channel.basicRecover(true);
    }
    if (!recover) RabbitMqListenerRegistry.registerListener(this, 10000);
    channel.addShutdownListener(new ShutdownListener() {
        @Override
        public void shutdownCompleted(ShutdownSignalException cause) {
            if (!cause.isInitiatedByApplication()) {
                log.error("Channel shutdown: " + cause.getMessage(), cause);
                log.info("Re creating channel..");
                try {
                    attachToQueue(true);
                } catch (IOException ex) {
                    log.error("Couldn't create new channel due to " + ex, ex);
                }
            } else {
                if (log.isDebugEnabled())
                    log.debug("Channel shutdown: " + cause.getMessage());
            }
        }
    });
    this.consumerTag = this.topicName() + ".__." + this.queueName() + UUID.randomUUID().toString();
    registerConsumer(channel, queueName, consumerTag);
}
 
开发者ID:datenstrudel,项目名称:bulbs-core,代码行数:32,代码来源:RabbitMqExchangeListener.java

示例8: ChannelHandler

import com.rabbitmq.client.ShutdownListener; //导入依赖的package包/类
public ChannelHandler(ConnectionHandler connectionHandler, Channel delegate, Config config) {
  this.connectionHandler = connectionHandler;
  this.delegate = delegate;
  this.config = config;

  ShutdownListener listener = new ChannelShutdownListener();
  shutdownListeners.add(listener);
  delegate.addShutdownListener(listener);
}
 
开发者ID:jhalterman,项目名称:lyra,代码行数:10,代码来源:ChannelHandler.java

示例9: create

import com.rabbitmq.client.ShutdownListener; //导入依赖的package包/类
@Override
public Connection create() throws Exception {
	ConnectionFactory factory = null;
	Connection connection = null;
	do {
		try {
			factory = pickOne();
			connection = factory.newConnection();
		} catch (Exception e) {
			logger.error("fail to create new connection from factory: [" + factory.getHost() + ":"
					+ factory.getPort() + "], kicking this one out and retry...");
			kick(factory.getHost() + ":" + factory.getPort());
		}
	} while (connection == null
			&& ConnectionFactoryManager.getInstance().getAvailableFactories().keySet().size() > 0);
	if (connection == null) {
		throw new Exception("fail to get new connection. no hosts left to use.");
	}
	/* ADD CONNECTION & CHANNEL CONNECTION LISTENER */
	connection.addShutdownListener(new ShutdownListener() {
		public void shutdownCompleted(ShutdownSignalException cause) {
			String hardError = "";
			String applInit = "";
			if (cause.isHardError()) {
				hardError = "connection";
			} else {
				hardError = "channel";
			}

			if (cause.isInitiatedByApplication()) {
				applInit = "application";
			} else {
				applInit = "broker";
			}
			logger.warn("Connectivity to MQ has failed.  It was caused by " + applInit + " at the " + hardError
					+ " level.  Reason received " + cause.getReason());
		}
	});

	((Recoverable) connection).addRecoveryListener(new RecoveryListener() {
		public void handleRecovery(Recoverable recoverable) {
			if (recoverable instanceof Connection) {
				logger.info("Connection was recovered.");
			} else if (recoverable instanceof Channel) {
				int channelNumber = ((Channel) recoverable).getChannelNumber();
				logger.info("Connection to channel #" + channelNumber + " was recovered.");
			}
		}

		public void handleRecoveryStarted(Recoverable arg0) {
		}
	});
	/* ADD CONNECTION & CHANNEL CONNECTION LISTENER */
	logger.info(
			"new connection was establesed...from host <- [" + factory.getHost() + ":" + factory.getPort() + "]");
	return connection;
}
 
开发者ID:WengShengyuan,项目名称:rabbit-mq-client,代码行数:58,代码来源:PooledConnectionFactory.java

示例10: addShutdownListener

import com.rabbitmq.client.ShutdownListener; //导入依赖的package包/类
@Override
public void addShutdownListener(ShutdownListener listener) {
  channel.addShutdownListener(listener);
}
 
开发者ID:opentracing-contrib,项目名称:java-rabbitmq-client,代码行数:5,代码来源:TracingChannel.java

示例11: removeShutdownListener

import com.rabbitmq.client.ShutdownListener; //导入依赖的package包/类
@Override
public void removeShutdownListener(ShutdownListener listener) {
  channel.removeShutdownListener(listener);
}
 
开发者ID:opentracing-contrib,项目名称:java-rabbitmq-client,代码行数:5,代码来源:TracingChannel.java

示例12: addShutdownListener

import com.rabbitmq.client.ShutdownListener; //导入依赖的package包/类
@Override
public void addShutdownListener(ShutdownListener listener) {
  this.mc.getUnderlyingConnection().addShutdownListener(listener);
}
 
开发者ID:leogsilva,项目名称:rabbitmq-resource-adapter,代码行数:5,代码来源:RabbitmqConnectionImpl.java

示例13: removeShutdownListener

import com.rabbitmq.client.ShutdownListener; //导入依赖的package包/类
@Override
public void removeShutdownListener(ShutdownListener listener) {
  this.mc.getUnderlyingConnection().removeShutdownListener(listener);
}
 
开发者ID:leogsilva,项目名称:rabbitmq-resource-adapter,代码行数:5,代码来源:RabbitmqConnectionImpl.java


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