/** * Publish a message to a topic. * * @param brokerMessage The Broker message containing the payload. * @param destination The destination name (e.g. /topic/foo). * @param acceptRequest An AcceptRequest object used handling Accept messages. */ public void publishMessage( NetBrokerMessage brokerMessage, String destination, AcceptRequest acceptRequest) { if ((brokerMessage != null) && (StringUtils.isNotBlank(destination))) { NetPublish publish = new NetPublish( destination, pt.com.broker.types.NetAction.DestinationType.TOPIC, brokerMessage); if (acceptRequest != null) { publish.setActionId(acceptRequest.getActionId()); PendingAcceptRequestsManager.addAcceptRequest(acceptRequest); } NetAction action = new NetAction(ActionType.PUBLISH); action.setPublishMessage(publish); NetMessage msg = buildMessage(action, brokerMessage.getHeaders()); try { getNetHandler().sendMessage(msg); } catch (Throwable e) { log.error("Could not publish message, messageId:"); log.error(e.getMessage(), e); } } else { throw new IllegalArgumentException("Mal-formed Publish request"); } }
/** * Publishes a message to a queue. * * @param brokerMessage The Broker message containing the payload. * @param destinationName The destination name (e.g. /queue/foo). * @param acceptRequest An AcceptRequest object used handling Accept messages. */ public void enqueueMessage( NetBrokerMessage brokerMessage, String destinationName, AcceptRequest acceptRequest) { if ((brokerMessage != null) && (StringUtils.isNotBlank(destinationName))) { NetPublish publish = new NetPublish( destinationName, pt.com.broker.types.NetAction.DestinationType.QUEUE, brokerMessage); if (acceptRequest != null) { publish.setActionId(acceptRequest.getActionId()); PendingAcceptRequestsManager.addAcceptRequest(acceptRequest); } NetAction action = new NetAction(ActionType.PUBLISH); action.setPublishMessage(publish); NetMessage msg = buildMessage(action, brokerMessage.getHeaders()); try { getNetHandler().sendMessage(msg); } catch (Throwable t) { log.error("Failed to deliver message.", t); } } else { throw new IllegalArgumentException("Mal-formed Enqueue request"); } }
public void publishMessage(final NetPublish np, final String messageSource) { StringBuilder sb_source = new StringBuilder(); sb_source.append("topic@"); sb_source.append(GcsInfo.getAgentName()); sb_source.append("://"); sb_source.append(np.getDestination()); sb_source.append("?app="); sb_source.append(messageSource); np.getMessage().addHeader(Headers.FROM, sb_source.toString()); Gcs.publish(np); }
public boolean enqueueMessage(final NetPublish np, String messageSource) { StringBuilder sb_source = new StringBuilder(); sb_source.append("queue@"); sb_source.append(GcsInfo.getAgentName()); sb_source.append("://"); sb_source.append(np.getDestination()); sb_source.append("?app="); sb_source.append(messageSource); np.getMessage().addHeader(Headers.FROM, sb_source.toString()); // Deferred delivery String defDeliveryStr = np.getMessage().getHeaders().get(Headers.DEFERRED_DELIVERY); if (!StringUtils.isBlank(defDeliveryStr)) { try { long value = Long.parseLong(defDeliveryStr); if (value < 0) { throw new NumberFormatException(); } // Set delivery delivery time np.getMessage() .getHeaders() .put(Headers.DEFERRED_DELIVERY, "" + (System.currentTimeMillis() + value)); } catch (NumberFormatException nfe) { log.warn( String.format( "Invalid value for '%s' header: '%s'. Ignoring and removing header. Destination queue: '%s'", Headers.DEFERRED_DELIVERY, defDeliveryStr, np.getDestination())); np.getMessage().getHeaders().remove(Headers.DEFERRED_DELIVERY); } } NetMessage nmsg = Gcs.buildNotification(np, np.getDestination()); return Gcs.enqueue(nmsg, np.getDestination()); }