void send() throws IOException { try { chan.basicPublish(exchange.toString(), serviceId, true, msg.getAMQPProperties(), data); } catch (ShutdownSignalException e) { if (!(conn instanceof AutorecoveringConnection) || serverIps.size() <= 1 || !Platform.IS_RUNNING) { // the connection is not recoverable throw e; } logger.warn(String.format("failed to send a message because %s; as the connection is recoverable," + "we are doing recoverable send right now", e.getMessage())); if (!recoverSend()) { throw e; } } }
public void send(final Message msg, boolean makeQueueName) { /* StopWatch watch = new StopWatch(); watch.start(); */ String serviceId = msg.getServiceId(); if (makeQueueName) { serviceId = makeMessageQueueName(serviceId); } buildSchema(msg); evalThreadContextToMessage(msg); if (logger.isTraceEnabled() && logMessage(msg)) { logger.trace(String.format("[msg send]: %s", wire.dumpMessage(msg))); } Channel chan = channelPool.acquire(); try { new RecoverableSend(chan, msg, serviceId, outboundQueue.getBusExchange()).send(); /* watch.stop(); logger.debug(String.mediaType("sending %s cost %sms", msg.getClass().getName(), watch.getTime())); */ } catch (IOException e) { throw new CloudRuntimeException(e); } finally { channelPool.returnChannel(chan); } }
public void publish(Event evt) { /* StopWatch watch = new StopWatch(); watch.start(); */ buildSchema(evt); evalThreadContextToMessage(evt); if (logger.isTraceEnabled() && logMessage(evt)) { logger.trace(String.format("[event publish]: %s", wire.dumpMessage(evt))); } Channel chan = channelPool.acquire(); try { new RecoverableSend(chan, evt, evt.getType().toString(), BusExchange.BROADCAST).send(); /* watch.stop(); logger.debug(String.mediaType("sending %s cost %sms", evt.getClass().getName(), watch.getTime())); */ } catch (IOException e) { throw new CloudRuntimeException(e); } finally { channelPool.returnChannel(chan); } }
RecoverableSend(Channel chan, Message msg, String serviceId, BusExchange exchange) throws IOException { data = compressMessageIfNeeded(msg); this.chan = chan; this.serviceId = serviceId; this.msg = msg; this.exchange = exchange; }