private void send(Message msg, Boolean noNeedReply) { if (msg.getServiceId() == null) { throw new IllegalArgumentException(String.format("service id cannot be null: %s", msg.getClass().getName())); } basicProperty(msg); msg.putHeaderEntry(CloudBus.HEADER_CORRELATION_ID, msg.getId()); msg.putHeaderEntry(CloudBus.HEADER_REPLY_TO, outboundQueue.getBindingKey()); if (msg instanceof APIMessage) { // API always need reply msg.putHeaderEntry(CloudBus.HEADER_NO_NEED_REPLY_MSG, Boolean.FALSE.toString()); } else if (msg instanceof NeedReplyMessage) { // for NeedReplyMessage sent without requiring receiver to reply, // mark it, then it will not be tracked and replied msg.putHeaderEntry(CloudBus.HEADER_NO_NEED_REPLY_MSG, noNeedReply.toString()); } buildRequestMessageMetaData(msg); wire.send(msg); }
outboundQueue = new BusQueue(makeMessageQueueName(SERVICE_ID), BusExchange.P2P); Channel chan = channelPool.acquire(); chan.queueDeclare(outboundQueue.getName(), false, false, true, queueArguments()); chan.basicConsume(outboundQueue.getName(), true, consumer); chan.queueBind(outboundQueue.getName(), outboundQueue.getBusExchange().toString(), outboundQueue.getBindingKey()); channelPool.returnChannel(chan); maid.construct();
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); } }