/** * Constructs the relayer which will immediately create a context and begin * listening for messages. */ public TopicMessageRelayer() { context = createContext(); consumer = context.createConsumer(TXN_TOPIC_QUEUE_DESTINATION); consumer.setMessageListener(this); }
public DemoQueueReader(HazelcastMQInstance hazelcastMQInstance) { mqContext = hazelcastMQInstance.createContext(); mqConsumer = mqContext.createConsumer("/queue/demo.queue"); mqConsumer.setMessageListener(new HazelcastMQMessageListener() { @Override public void onMessage(HazelcastMQMessage msg) { log.info("Read data: {}", msg.getBodyAsString()); } }); }
/** * 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); }
@Override public void send(String body) { // Construct a message HazelcastMQMessage msg = new HazelcastMQMessage(); msg.setBody(body); send(msg); }
public HazelcastMQContext createContext(boolean transacted) { HazelcastMQContext mqContext = mqInstance.createContext(transacted); mqContext.start(); return mqContext; }
/** * 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); } /**
@Override public Object fromMessage(HazelcastMQMessage message) throws HazelcastMQException { try { return doFromMessage(message); } catch (IOException ex) { throw new HazelcastMQException( "IO error converting message to message bytes.", ex); } }
@Override public HazelcastMQMessage toMessage(Object msgData) throws HazelcastMQException { try { return doToMessage((byte[]) msgData); } catch (IOException ex) { throw new HazelcastMQException( "IO error converting message bytes to a message.", ex); } }
public XAHazelcastMQContext createXAContext() { XAHazelcastMQContext mqContext = mqInstance.createXAContext(); mqContext.start(); return mqContext; }
@Override public void send(byte[] body) { // Construct a message HazelcastMQMessage msg = new HazelcastMQMessage(); msg.setBody(body); send(msg); }
/** * 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); }
public HazelcastMQContext createContext(boolean transacted) { HazelcastMQContext mqContext = mqInstance.createContext(transacted); mqContext.start(); return mqContext; }
/** * 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); }
@Override public void send(String destination, byte[] body) { // Construct a message HazelcastMQMessage msg = new HazelcastMQMessage(); msg.setBody(body); send(destination, msg); }
/** * 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); }
/** * 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); }