本文整理汇总了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.");
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
}
示例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.");
}
示例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);
}
}
示例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;
}
示例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) ;
}
示例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;
}
}
}
示例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());
}
}
}
示例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());
}
}
}
示例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);
}
}