當前位置: 首頁>>代碼示例>>Java>>正文


Java ShutdownSignalException類代碼示例

本文整理匯總了Java中com.rabbitmq.client.ShutdownSignalException的典型用法代碼示例。如果您正苦於以下問題:Java ShutdownSignalException類的具體用法?Java ShutdownSignalException怎麽用?Java ShutdownSignalException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ShutdownSignalException類屬於com.rabbitmq.client包,在下文中一共展示了ShutdownSignalException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initRabbitMQ

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的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: declareQueue

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的package包/類
@Override
public void declareQueue() throws IOException {

    RabbitAdmin rabbitAdmin = rabbitAdmin();

    try {
        rabbitAdmin.declareQueue(new Queue("demo2",false,false,false));
    }catch (Exception e){
        try {
            if (406 == ((AMQImpl.Channel.Close) ((ShutdownSignalException)e.getCause().getCause()).getReason()).getReplyCode()) {
                rabbitAdmin.deleteQueue("demo2");
                declareQueue();
            }
        }catch (Exception e1){
        }
        log.error("e 's value : {}", e);
    }


}
 
開發者ID:laidu,項目名稱:java-learn,代碼行數:21,代碼來源:SpringClientDemo.java

示例3: main

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的package包/類
/**
 * @param args
 * @throws TimeoutException
 * @throws IOException
 * @throws InterruptedException
 * @throws ConsumerCancelledException
 * @throws ShutdownSignalException
 */
public static void main(String[] args) throws IOException, TimeoutException, ShutdownSignalException,
		ConsumerCancelledException, InterruptedException {
	ConnectionFactory factory = new ConnectionFactory();
	factory.setHost(host);
	factory.setUsername(username);
	factory.setPassword(password);
	factory.setPort(port);
	factory.setVirtualHost(virtualHost);
	Connection connection = factory.newConnection();
	Channel channel = connection.createChannel();
	channel.queueDeclare(RPC_QUEUE_NAME, false, false, false, null);
	channel.basicQos(1);
	QueueingConsumer consumer = new QueueingConsumer(channel);
	channel.basicConsume(RPC_QUEUE_NAME, false, consumer);

	System.out.println("RPCServer Awating RPC request");
	while (true) {
		QueueingConsumer.Delivery delivery = consumer.nextDelivery();
		BasicProperties props = delivery.getProperties();
		BasicProperties replyProps = new AMQP.BasicProperties.Builder().correlationId(props.getCorrelationId())
				.build();

		String message = new String(delivery.getBody(), "UTF-8");
		int n = Integer.parseInt(message);

		System.out.println("RPCServer fib(" + message + ")");
		String response = "" + fib(n);
		channel.basicPublish("", props.getReplyTo(), replyProps, response.getBytes());
		channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
	}
}
 
開發者ID:pudoj,項目名稱:june.mq,代碼行數:40,代碼來源:RPCServer.java

示例4: doThrow

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的package包/類
@Test
public void testConnection_WithOpenStack_WithIgnoreControllerException_WithIgnoreProviderException_WhenRabbitClientConnectionThrowsSignalException_ThrowsErrorTypeException() throws Throwable {
    // Arrange.
    this.exception.expect(ErrorTypeException.class);

    DryRunRequest<VirtualizationConnectorRequest> request = VirtualizationConnectorUtilTestData.generateOpenStackVCWithSDN();

    List<ErrorType> errorList = new ArrayList<>();
    errorList.add(ErrorType.CONTROLLER_EXCEPTION);
    errorList.add(ErrorType.PROVIDER_EXCEPTION);
    request.addErrorsToIgnore(errorList);

    VirtualizationConnector vc = VirtualizationConnectorEntityMgr.createEntity(request.getDto(), this.encrypter);
    doThrow(mock(ShutdownSignalException.class)).when(this.rabbitClient).testConnection();
    DryRunRequest<VirtualizationConnectorRequest> spyRequest = spy(request);

    // Act.
    this.util.checkConnection(spyRequest, vc);

    // Assert.
    verify(spyRequest, times(1)).isIgnoreErrorsAndCommit(ErrorType.CONTROLLER_EXCEPTION);
    verify(spyRequest, times(1)).isIgnoreErrorsAndCommit(ErrorType.PROVIDER_EXCEPTION);
    verify(this.rabbitClient, times(1)).testConnection();
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:25,代碼來源:VirtualizationConnectorUtilTest.java

示例5: startSyncReceiveThread

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的package包/類
private void startSyncReceiveThread(final QueueingConsumer consumer, final boolean autoAck, final BindingVo binding) {
	syncReceiveThread = new SyncReceiveThread() {
		@Override
		public void run() {
			log.info("start listen to the " + typeStr + "[" + queue.getName() + "].");
			while (running) {
				try {
					QueueingConsumer.Delivery delivery = consumer.nextDelivery();
					XCO xcoMessage = getMessage(delivery.getBody());
					log.info("received a message from " + typeStr + "[" + queue.getName() + "]: " + xcoMessage);
					boolean result = exec(service, xcoMessage, binding);
					if (!autoAck && result) {
						channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
					}
				} catch (ShutdownSignalException e) {
					// TODO 可能會出現斷鏈的問題
					e.printStackTrace();
				} catch (Throwable e) {
					log.error("listen to the [" + queue.getName() + "] error.", e);
				}
			}
			closed = true;
		}
	};
	syncReceiveThread.start();
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:27,代碼來源:RabbitMqReceiver.java

示例6: send

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的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

示例7: shutdownCompleted

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的package包/類
@Override
public void shutdownCompleted(final ShutdownSignalException shutdownSignalException) {
    if (!shutdownSignalException.isInitiatedByApplication()) {

        for (final String subscriberId : s_subscribers.keySet()) {
            final Ternary<String, Channel, EventSubscriber> subscriberDetails = s_subscribers.get(subscriberId);
            subscriberDetails.second(null);
            s_subscribers.put(subscriberId, subscriberDetails);
        }

        abortConnection(); // disconnected to AMQP server, so abort the connection and channels
        s_logger.warn("Connection has been shutdown by AMQP server. Attempting to reconnect.");

        // initiate re-connect process
        final ReconnectionTask reconnect = new ReconnectionTask();
        executorService.submit(reconnect);
    }
}
 
開發者ID:MissionCriticalCloud,項目名稱:cosmic,代碼行數:19,代碼來源:RabbitMQEventBus.java

示例8: destroy

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的package包/類
public void destroy(){
	
	log.debug("Destroying '" + CMPT_NAME + "' component");
	
	if(null != conn){
		try{
			if(conn.isOpen()){ conn.close(); }
			conn = null;
			
		}catch(IOException ioe){
			log.error("IOException while destroying "+ CMPT_NAME +" component: ", ioe);				
		}catch(ShutdownSignalException sse){
			log.error("Shutdown Exception while destroying "+ CMPT_NAME + " component: ", sse);
		}catch(Exception e){
			log.error("Caught unhandled exception while destroying " + CMPT_NAME + 
					" component: ", e);
		}
	}
	
	log.info("\tdestroyed.");
}
 
開發者ID:hadrsystems,項目名稱:nics-common,代碼行數:22,代碼來源:RabbitProducer.java

示例9: readOneMessage

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的package包/類
/***
 * getParam().getWaitTime() 指定消息池為空時的堵塞超時
 * 
 */
@Override
public String readOneMessage()
{
  try
  {
    channel.basicConsume(getParam().getQueue(), false, consumer);
    QueueingConsumer.Delivery delivery = consumer.nextDelivery(getParam().getWaitTime());
    if (delivery != null)
    {
      deliveryTag = delivery != null ? delivery.getEnvelope().getDeliveryTag() : deliveryTag;
      String msg = getMessageContent(delivery);
      return msg;
    }
    else
      return null;
  }
  catch (IOException | ShutdownSignalException | ConsumerCancelledException | InterruptedException e)
  {
    throw new MqReceiveException(e);
  }
}
 
開發者ID:iisi-nj,項目名稱:GemFireLite,代碼行數:26,代碼來源:RabbitMqReceiver.java

示例10: close

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的package包/類
public final void close() throws IOException, ShutdownSignalException
{        
    if (this.channel != null)
    {
        this.channel.close();
        Log.d("libretalk::LibretalkConnection", "Closed LibretalkConnection#channel");
    }
    
    if (this.connection != null)
    {
        this.connection.close();
        Log.d("libretalk::LibretalkConnection", "Closed LibretalkConnection#connection");
    }
    
    this.status = ConnectionStatus.NOT_CONNECTED;        
}
 
開發者ID:coderdojowaterford,項目名稱:libretalk,代碼行數:17,代碼來源:LibretalkConnection.java

示例11: sendMessage

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的package包/類
public void sendMessage(File messageFile) throws IOException, ShutdownSignalException, InterruptedException{
	InputStream is = new FileInputStream(messageFile);

    // Get the size of the file
    long length = messageFile.length();
    if (length > Integer.MAX_VALUE) {
    	throw new IOException("Input File ("+messageFile.getName()+") is to large! ");
    }
    byte[] messageBodyBytes = new byte[(int)length];
    int offset = 0;
    int numRead = 0;
    while (offset < messageBodyBytes.length
           && (numRead=is.read(messageBodyBytes, offset, messageBodyBytes.length-offset)) >= 0) {
        offset += numRead;
    }
    if (offset < messageBodyBytes.length) {
        throw new IOException("Could not completely read file "+messageFile.getName());
    }
    is.close();
	this.channel.basicPublish(this.ExchangeName, this.RoutingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, messageBodyBytes) ;
	
}
 
開發者ID:Data-to-Insight-Center,項目名稱:komadu,代碼行數:23,代碼來源:Sender.java

示例12: closeConnection

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的package包/類
/**
 * Helper method to close connection in RMQChannel
 *
 * @throws ShutdownSignalException
 * @throws IOException
 * @throws AlreadyClosedException
 */
public void closeConnection() throws ShutdownSignalException, IOException, AlreadyClosedException{
    if (connection != null) {
        try {
            channel.close();
        } catch (Exception e) {
            //ignore as the connection gets closed anyway
        }
        channel = null;
        try {
            connection.close();
        } finally {
            connection = null;
        }
    }
}
 
開發者ID:wso2,項目名稱:wso2-axis2-transports,代碼行數:23,代碼來源:RMQChannel.java

示例13: run

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的package包/類
@Override
public void run() {
    while(!shutdown) {
        try {
            Thread.yield();
            buffer.waitNotEmpty();
            observer.onCallback();
        } catch(ShutdownSignalException e) {
            shutdown=true;
            log.debug("closed connection of receiver.");
        } catch(Throwable t) {
            log.error(t.getMessage());
            t.printStackTrace();
            System.exit(-1);
            throw new RuntimeException("Problem during run! "+t.getMessage());
        }
    }
}
 
開發者ID:yatsdev,項目名稱:AllGoTrading,代碼行數:19,代碼來源:BufferingReceiver.java

示例14: run

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的package包/類
@Override
    public void run() {
        while(!shutdown) {
            try {
                Thread.yield();
                T m = receive();
//                log.info("got:" + m.toString());
                if(buffer!=null) {
                    log.error("previous packet has not been picket up! discarded:"+buffer);
                }
                buffer = m;
                observer.onCallback();
            } catch(ShutdownSignalException e) {
                shutdown=true;
                log.debug("closed connection");
            } catch(Throwable t) {
                log.error(t.getMessage());
                t.printStackTrace();
                System.exit(-1);
                throw new RuntimeException("Problem during run! "+t.getMessage());
            }
        }
    }
 
開發者ID:yatsdev,項目名稱:AllGoTrading,代碼行數:24,代碼來源:CallingReceiver.java

示例15: shutdownCompleted

import com.rabbitmq.client.ShutdownSignalException; //導入依賴的package包/類
@Override
public void shutdownCompleted(ShutdownSignalException shutdownSignalException) {
    if (!shutdownSignalException.isInitiatedByApplication()) {

        for (String subscriberId : s_subscribers.keySet()) {
            Ternary<String, Channel, EventSubscriber> subscriberDetails = s_subscribers.get(subscriberId);
            subscriberDetails.second(null);
            s_subscribers.put(subscriberId, subscriberDetails);
        }

        abortConnection(); // disconnected to AMQP server, so abort the connection and channels
        s_logger.warn("Connection has been shutdown by AMQP server. Attempting to reconnect.");

        // initiate re-connect process
        ReconnectionTask reconnect = new ReconnectionTask();
        executorService.submit(reconnect);
    }
}
 
開發者ID:apache,項目名稱:cloudstack,代碼行數:19,代碼來源:RabbitMQEventBus.java


注:本文中的com.rabbitmq.client.ShutdownSignalException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。