/** * Sets the ID of the message. This is a convenience method for setting the * {@link Headers#MESSAGE_ID} value. * * @param id the ID of the message */ public void setId(String id) { getHeaders().put(Headers.MESSAGE_ID, id); }
/** * Sets the correlation ID of the message. This is a convenience method for * setting the {@link Headers#CORRELATION_ID} value. * * @param correlationId the correlation ID of the message */ public void setCorrelationId(String correlationId) { getHeaders().put(Headers.CORRELATION_ID, correlationId); }
/** * Returns the correlation ID of the message. This is a convenience method for * getting the {@link Headers#CORRELATION_ID} value. * * @return the correlation ID of the message */ public String getCorrelationId() { return getHeaders().get(Headers.CORRELATION_ID); } /**
/** * Returns the content type of the message. This is a convenience method for * getting the {@link Headers#CONTENT_TYPE} value. * * @return the content type of the message */ public String getContentType() { return getHeaders().get(Headers.CONTENT_TYPE); }
/** * Sets the reply to destination of the message. This is a convenience method * for setting the {@link Headers#REPLY_TO} value. * * @param destination the reply to destination */ public void setReplyTo(String destination) { getHeaders().put(Headers.REPLY_TO, destination); }
/** * Sets the content type of the message. This is a convenience method for * setting the {@link Headers#CONTENT_TYPE} value. * * @param contentType * the content type to set */ public void setContentType(String contentType) { getHeaders().put(Headers.CONTENT_TYPE, contentType); }
/** * Returns the reply to destination of the message. This is a convenience * method for getting the {@link Headers#REPLY_TO} value. * * @return the reply to destination */ public String getReplyTo() { return getHeaders().get(Headers.REPLY_TO); }
/** * Returns the destination of the message. This is a convenience method for * getting the {@link Headers#DESTINATION} value. * * @return the destination */ public String getDestination() { return getHeaders().get(Headers.DESTINATION); }
/** * Returns the ID of the message. This is a convenience method for getting the * {@link Headers#MESSAGE_ID} value. * * @return the id of the message */ public String getId() { return getHeaders().get(Headers.MESSAGE_ID); }
/** * Sets the destination of the message. This is a convenience method for * setting the {@link Headers#DESTINATION} value. * * @param destination * the destination to set */ public void setDestination(String destination) { getHeaders().put(Headers.DESTINATION, destination); }
/** * Returns the body as a String using the character set encoding in the * content-type header or UTF-8 if no character set is specified in the * headers. If there is no body to the message, null is returned. This is just * a convenience method for {@link #getBody() }. * * @return the body as a string or null */ public String getBodyAsString() { Charset charset = UTF_8; String contentType = getHeaders().get(Headers.CONTENT_TYPE); if (contentType != null && contentType.contains(";")) { String[] parts = contentType.split(";"); for (String part : parts) { if (part.startsWith("charset=")) { charset = Charset.forName(part.substring("charset=".length())); } } } return getBodyAsString(charset); }
private byte[] doFromMessage(HazelcastMQMessage message) throws IOException { ByteArrayOutputStream outstream = new ByteArrayOutputStream(); // BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( // outstream, UTF_8)); // Command writeLine(outstream, MESSAGE_COMMAND); // Write the general headers HazelcastMQMessage hzMessage = message; marshalHeaders(hzMessage.getHeaders(), outstream); byte[] body = message.getBody(); if (body != null) { write(outstream, HEADER_CONTENT_LENGTH); outstream.write(':'); writeLine(outstream, String.valueOf(body.length)); // Blank line to start the body. outstream.write(NEWLINE); outstream.write(body); } else { outstream.write(NEWLINE); } // Write the terminating NULL character. outstream.write((byte) NULL_CHARACTER); return outstream.toByteArray(); }
@Override public Frame toFrame(HazelcastMQMessage msg) { FrameBuilder fb = FrameBuilder.command(Command.MESSAGE); fb.body(msg.getBody()); for (String name : msg.getHeaders().getHeaderNames()) { String value = msg.getHeaders().get(name); fb.header(name, value); } return fb.build(); } }
message.getHeaders().put(key, value);
mqMsg.getHeaders().put(MQ_HEADER_JMS_HEADER_PREFIX + entry.getKey(), entry.getValue()); mqMsg.getHeaders().put(MQ_HEADER_JMS_PROPERTY_PREFIX + entry.getKey(), entry.getValue()); HazelcastMQJmsDestination replyToDest = (HazelcastMQJmsDestination) jmsMsg .getJMSReplyTo(); mqMsg.getHeaders().put(Headers.REPLY_TO, replyToDest.getMqName()); mqMsg.getHeaders().put(Headers.CORRELATION_ID, jmsMsg.getJMSCorrelationID()); mqMsg.getHeaders().put(Headers.CONTENT_LENGTH, String.valueOf(body.length));
for (Map.Entry<String, Object> camelHeader : camelHeaders.entrySet()) { if (camelHeader.getValue() instanceof String) { mqMsg.getHeaders().put(camelHeader.getKey(), (String) camelHeader. getValue());
/** * Sends a reply message if the exchange has a valid message in the out or * in fields (in that order). * * @param correlationId the optional correlation ID to set on the out going * message * @param replyToDestination the reply to destination * @param camelExchange the exchange containing the message to send as the * reply */ private void sendReply(String correlationId, String replyToDestination, Exchange camelExchange) { Message camelMsg = camelExchange.hasOut() ? camelExchange.getOut() : camelExchange.getIn(); if (camelMsg != null) { try { HazelcastMQMessage msg = messageConverter.fromCamelMessage(camelMsg); msg.getHeaders().remove(org.mpilone.hazelcastmq.core.Headers.REPLY_TO); msg.setDestination(replyToDestination); msg.setCorrelationId(correlationId); mqContext.createProducer(replyToDestination).send(msg); } catch (Throwable ex) { camelExchange.setException(ex); } } } }
@Override public HazelcastMQMessage fromFrame(Frame frame) { HazelcastMQMessage msg = new HazelcastMQMessage(); org.mpilone.yeti.Headers headers = frame.getHeaders(); for (String name : headers.getHeaderNames()) { String value = headers.get(name); msg.getHeaders().put(name, value); } msg.setBody(frame.getBody()); return msg; }
msg.getHeaders().put(Headers.EXPIRATION, String.valueOf(System.currentTimeMillis() + timeToLive));
/** * Converts from a Camel message to a HzMq message. The headers are simply * copied unmodified. The body is mapped by type: * <ul> * <li>If the content type is text/plain, the body is set as a String</li> * <li>all others: the body is set as a byte[] (or null)</li> * </ul> * * @param mqMsg the HzMq message to convert * * @return the new Camel message */ @Override public Message toCamelMessage(HazelcastMQMessage mqMsg) { DefaultMessage camelMsg = new DefaultMessage(); camelMsg.setHeaders((Map) mqMsg.getHeaders().getHeaderMap()); if (mqMsg.getContentType() != null && mqMsg.getContentType().equals( "text/plain")) { camelMsg.setBody(mqMsg.getBodyAsString()); } else { camelMsg.setBody(mqMsg.getBody()); } return camelMsg; } }