public void close() throws JMSException { if (consumer != null) { try { consumer.close(); } catch (HornetQException e) { throw JMSExceptionHelper.convertFromHornetQException(e); } } }
protected ClientMessage receiveFromConsumer(long timeoutSecs) throws Exception { ClientMessage m = null; if (timeoutSecs <= 0) { m = consumer.receive(1); } else { m = consumer.receive(timeoutSecs * 1000); } HornetQRestLogger.LOGGER.debug("Returning message " + m + " from consumer: " + consumer); return m; }
/** * enables real-time receiving for this {@link Microservice} * */ void enableRealTimeReceiving() { if (consumer == null || consumer.isClosed()) return; listener = new MessageListener(new MessageCallback(name)); try { consumer.setMessageHandler(listener); } catch (Exception e) { listener = null; } }
/** * disables real-time receiving for this {@link Microservice} * */ void disableRealTimeReceiving() { try { if (consumer == null || listener == null || consumer.getMessageHandler() == null) return; listener = null; consumer.setMessageHandler(null); } catch (Exception exp) { logError(MODULE_NAME, exp.getMessage(), exp); } }
" on bridge " + this.getName()); notifConsumer.close(); notifConsumer.setMessageHandler(flowRecord);
message = consumer.receiveImmediate(); message = consumer.receive(timeout);
public void setMessageListener(final MessageListener listener) throws JMSException { this.listener = listener; coreListener = listener == null ? null : new JMSMessageListenerWrapper(session, consumer, listener, ackMode); try { consumer.setMessageHandler(coreListener); } catch (HornetQException e) { throw JMSExceptionHelper.convertFromHornetQException(e); } }
boolean isConsumerClosed(String name) { ClientConsumer consumer = consumers.get(name); return consumer == null || consumer.isClosed(); }
public boolean hasMoreElements() { if (current == null) { try { current = consumer.receiveImmediate(); } catch (HornetQException e) { return false; } } return current != null; }
" on bridge " + this.getName()); notifConsumer.close(); notifConsumer.setMessageHandler(flowRecord);
consumer.setMessageHandler(new PushConsumerMessageHandler(this, session)); session.start(); HornetQRestLogger.LOGGER.startingPushConsumer(registration.getTarget());
if (!consumer.isClosed() && !transactedOrClientAck)
/** * receives only one {@link Message} * * @return {@link Message} * @throws Exception */ private Message getMessage() throws Exception { if (consumer == null || listener != null) return null; Message result = null; ClientMessage msg; synchronized (messageBusSessionLock) { msg = consumer.receiveImmediate(); } if (msg != null) { msg.acknowledge(); result = new Message(msg.getBytesProperty("message")); } return result; }
/** * Closes the passed-in {@link ClientConsumer}. * * @param consumer the {@link ClientConsumer} instance to close. */ public static void closeClientConsumer(final ClientConsumer consumer) { if (consumer != null) { try { consumer.close(); } catch (final HornetQException ignore) { ignore.printStackTrace(); } } }
@Override public void run() { while (!shutdown.get()) { try { ClientMessage message = consumer.receive(500); if (message == null) { continue; } String s = message.getStringProperty(BODY); log.info("-----> Received: " + s); synchronized (receivedMessages) { receivedMessages.add(s); } } catch (HornetQException e) { log.error("Exception, closing receiver", e); } } } }).start();
/** * creates IOFog message queues, {@link ClientMessage} producer * and {@link ClientSession} * * @throws Exception */ void initialize() throws Exception { synchronized (messageBusSessionLock) { messageBusSession = sf.createSession(true, true, 0); QueueQuery queueQuery = messageBusSession.queueQuery(new SimpleString(Constants.ADDRESS)); if (queueQuery.isExists()) messageBusSession.deleteQueue(Constants.ADDRESS); queueQuery = messageBusSession.queueQuery(new SimpleString(Constants.COMMAND_LINE_ADDRESS)); if (queueQuery.isExists()) messageBusSession.deleteQueue(Constants.COMMAND_LINE_ADDRESS); messageBusSession.createQueue(Constants.ADDRESS, Constants.ADDRESS, false); messageBusSession.createQueue(Constants.COMMAND_LINE_ADDRESS, Constants.COMMAND_LINE_ADDRESS, false); commandlineProducer = messageBusSession.createProducer(Constants.COMMAND_LINE_ADDRESS); commandlineConsumer = messageBusSession.createConsumer(Constants.COMMAND_LINE_ADDRESS, String.format("receiver = '%s'", "iofog.commandline.command")); commandlineConsumer.setMessageHandler(new CommandLineHandler()); messageBusSession.start(); } }
/** * Closes the passed-in {@link ClientConsumer}. * * @param consumer the {@link ClientConsumer} instance to close. */ public static void closeClientConsumer(final ClientConsumer consumer) { if (consumer != null) { try { consumer.close(); } catch (final HornetQException ignore) { ignore.printStackTrace(); } } }
/** * Sends a message to the request address and wait for the given timeout for a reply. * The temporary queue is used for the REPLYTO_HEADER_NAME, and only one reply per request is expected * * @param request the message to send * @param timeout the timeout to wait for a reply (in milliseconds) * @return the reply message or <code>null</code> if no message is replied before the timeout elapses * @throws Exception */ public ClientMessage request(final ClientMessage request, final long timeout) throws Exception { request.putStringProperty(ClientMessageImpl.REPLYTO_HEADER_NAME, replyQueue); requestProducer.send(request); return replyConsumer.receive(timeout); }
public void close() { if (consumer == null) return; disableRealTimeReceiving(); try { consumer.close(); } catch (Exception exp) { logError(MODULE_NAME, exp.getMessage(), exp); } } }
/** * Sends a message to the request address and wait for the given timeout for a reply. * The temporary queue is used for the REPLYTO_HEADER_NAME, and only one reply per request is expected * * @param request the message to send * @param timeout the timeout to wait for a reply (in milliseconds) * @return the reply message or {@code null} if no message is replied before the timeout elapses * @throws Exception */ public ClientMessage request(final ClientMessage request, final long timeout) throws Exception { request.putStringProperty(ClientMessageImpl.REPLYTO_HEADER_NAME, replyQueue); requestProducer.send(request); return replyConsumer.receive(timeout); }