@Override public void sendMessage(String txt) throws Exception { System.out.println("-----> Attempting to send message"); ClientProducer producer = session.createProducer(QUEUE_EXAMPLE_QUEUE); ClientMessage message = session.createMessage(false); message.putStringProperty(BODY, "'" + txt + "' sent at " + new Date()); System.out.println("-----> Sending message"); producer.send(message); }
boolean isProducerClosed(String name) { ClientProducer producer = producers.get(name); return producer == null || producer.isClosed(); }
public void close() throws JMSException { try { producer.close(); } catch (HornetQException e) { throw JMSExceptionHelper.convertFromHornetQException(e); } }
/** * Closes the passed-in {@link ClientProducer}. * * @param producer the {@link ClientProducer} to close. */ public static void closeClientProducer(final ClientProducer producer) { if (producer != null) { try { producer.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); }
/** * Closes the passed-in {@link ClientProducer}. * * @param producer the {@link ClientProducer} to close. */ public static void closeClientProducer(final ClientProducer producer) { if (producer != null) { try { producer.close(); } catch (final HornetQException ignore) { ignore.printStackTrace(); } } }
private void checkClosed() throws JMSException { if (producer.isClosed()) { throw new IllegalStateException("Producer is closed"); } }
/** * 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); }
/** * Closes the ClientRequestor and its session. * * @throws Exception if an exception occurs while closing the ClientRequestor */ public void close() throws Exception { replyConsumer.close(); requestProducer.close(); queueSession.deleteQueue(replyQueue); }
public void run() { try { producer.send(dest, message); // as soon as we are done sending the large message // we unset the delivery flag and we will call the deliveryAsync on the queue // so the bridge will be able to resume work unsetLargeMessageDelivery(); if (queue != null) { queue.deliverAsync(); } } catch (final HornetQException e) { unsetLargeMessageDelivery(); log.warn("Unable to send message " + ref + ", will try again once bridge reconnects", e); connectionFailed(e, false); } } });
private void closeChildren() throws HornetQException { Set<ClientConsumerInternal> consumersClone = cloneConsumers(); for (ClientConsumer consumer : consumersClone) { consumer.close(); } Set<ClientProducerInternal> producersClone = cloneProducers(); for (ClientProducer producer : producersClone) { producer.close(); } }
public void run() { try { producer.send(dest, message); // as soon as we are done sending the large message // we unset the delivery flag and we will call the deliveryAsync on the queue // so the bridge will be able to resume work unsetLargeMessageDelivery(); if (queue != null) { queue.deliverAsync(); } } catch (final HornetQException e) { unsetLargeMessageDelivery(); HornetQServerLogger.LOGGER.bridgeUnableToSendMessage(e, ref); connectionFailed(e, false); } } });
private void closeChildren() throws HornetQException { Set<ClientConsumerInternal> consumersClone = cloneConsumers(); for (ClientConsumer consumer : consumersClone) { consumer.close(); } Set<ClientProducerInternal> producersClone = cloneProducers(); for (ClientProducer producer : producersClone) { producer.close(); } }
/** * @param ref * @param message * @return */ private HandleStatus deliverStandardMessage(SimpleString dest, final MessageReference ref, ServerMessage message) { // if we failover during send then there is a chance that the // that this will throw a disconnect, we need to remove the message // from the acks so it will get resent, duplicate detection will cope // with any messages resent if (log.isTraceEnabled()) { log.trace("going to send message " + message); } try { producer.send(dest, message); } catch (final HornetQException e) { log.warn("Unable to send message " + ref + ", will try again once bridge reconnects", e); // We remove this reference as we are returning busy which means the reference will never leave the Queue. // because of this we have to remove the reference here refs.remove(ref); connectionFailed(e, false); return HandleStatus.BUSY; } return HandleStatus.HANDLED; }
producers.forEach((key, value) -> { try { value.close(); } catch (HornetQException e) { LoggingService.logInfo(MODULE_NAME, e.getMessage());
/** * @param ref * @param message * @return */ private HandleStatus deliverStandardMessage(SimpleString dest, final MessageReference ref, ServerMessage message) { // if we failover during send then there is a chance that the // that this will throw a disconnect, we need to remove the message // from the acks so it will get resent, duplicate detection will cope // with any messages resent if (HornetQServerLogger.LOGGER.isTraceEnabled()) { HornetQServerLogger.LOGGER.trace("going to send message " + message); } try { producer.send(dest, message); } catch (final HornetQException e) { HornetQServerLogger.LOGGER.bridgeUnableToSendMessage(e, ref); // We remove this reference as we are returning busy which means the reference will never leave the Queue. // because of this we have to remove the reference here refs.remove(ref); connectionFailed(e, false); return HandleStatus.BUSY; } return HandleStatus.HANDLED; }
public void connectionFailed(final HornetQException me, boolean failedOver) { HornetQServerLogger.LOGGER.bridgeConnectionFailed(me, failedOver); synchronized (connectionGuard) { keepConnecting = true; } try { if (producer != null) { producer.close(); } cleanUpSessionFactory(csf); } catch (Throwable dontCare) { } try { session.cleanUp(false); } catch (Throwable dontCare) { } fail(me.getType() == HornetQExceptionType.DISCONNECTED); tryScheduleRetryReconnect(me.getType()); }
System.out.println("Sending the message."); producer.send(message);
public void connectionFailed(final HornetQException me, boolean failedOver) { log.warn(this + "::Connection failed with failedOver=" + failedOver + "-" + me, me); try { if (producer != null) { producer.close(); } csf.cleanup(); } catch (Throwable dontCare) { } try { session.cleanUp(false); } catch (Throwable dontCare) { } fail(me.getCode() == HornetQException.DISCONNECTED); tryScheduleRetryReconnect(me.getCode()); }