/** * Send a message to an address. The message is either an {@link IEnvelope} which contains an * {@link IInternalMessage} or a {@link Map} with an "address" parameter. This makes it easier to * support both dynamic Javascript messages and more type safe Java messages. * * <p>Send attaches a "replyTo" address and a correlationId to them message so that it returns the * the {@link IBpmScriptEngine} */ @SuppressWarnings("unchecked") public void send( final String fromPid, final String fromBranch, final String fromVersion, final String queueId, Object message) throws BpmScriptException { String correlationId = correlationIdFormatter.format(fromPid, fromBranch, fromVersion, queueId); if (message instanceof IEnvelope) { IEnvelope envelope = (IEnvelope) message; InvocationMessage invocationMessage = ((InvocationMessage) envelope.getMessage()); invocationMessage.setReplyTo(replyTo); invocationMessage.setCorrelationId(correlationId); String address = (String) envelope.getAddress(); sender.send(address, invocationMessage); } else { Map<String, Object> map = (Map<String, Object>) message; map.put("correlationId", correlationId); map.put("replyTo", replyTo); String address = (String) map.get("address"); MapInvocationMessage result = new MapInvocationMessage(map); if (address == null) { log.warn("address for message " + result.toString() + " is null"); } sender.send(address, result); } }
/** * Send a message to an address. The message is either an {@link IEnvelope} which contains an * {@link IInternalMessage} or a {@link Map} with an "address" parameter. This makes it easier to * support both dynamic Javascript messages and more type safe Java messages. */ @SuppressWarnings("unchecked") public void sendOneWay(Object message) throws BpmScriptException { if (message instanceof IEnvelope) { IEnvelope envelope = (IEnvelope) message; sender.send((String) envelope.getAddress(), (IInternalMessage) envelope.getMessage()); } else { Map<String, Object> map = (Map<String, Object>) message; String address = (String) map.get("address"); MapInvocationMessage result = new MapInvocationMessage(map); if (address == null) { log.warn("address for message " + result.toString() + " is null"); } sender.send(address, result); } }