@Override void apply(MessageProducer producer, Destination destination, Message message) throws JMSException { ((QueueSender) producer).send((Queue) destination, message); } },
protected synchronized void sendMessage(Message message) throws JMSException { if (producer == null && createProducer() == null) { throw new JMSException("Producer for remote queue not available."); } try { producer.send(producerQueue, message); } catch (JMSException e) { producer = null; throw e; } }
/** Sends a request and waits for a reply. The temporary queue is used for * the {@code JMSReplyTo} destination, and only one reply per request * is expected. * * @param message the message to send * * @return the reply message * * @exception JMSException if the JMS provider fails to complete the * request due to some internal error. */ public Message request(Message message) throws JMSException { message.setJMSReplyTo(tempQueue); sender.send(message); return (receiver.receive()); }
@Override public void send(Queue queue, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException { checkQueueSender(); QueueSender qs = (QueueSender) delegate; Span span = createAndStartProducerSpan(null, message); SpanInScope ws = tracer.withSpanInScope(span); // animal-sniffer mistakes this for AutoCloseable try { qs.send(queue, message, deliveryMode, priority, timeToLive); } catch (RuntimeException | JMSException | Error e) { span.error(e); throw e; } finally { ws.close(); span.finish(); } }
sender.send(msg); } catch (final Exception e) { throw new JobExecutionException(e.getMessage());
@Test public void processAndReply() throws JMSException { MessagingMessageListenerAdapter listener = createDefaultInstance(String.class); String body = "echo text"; String correlationId = "link-1234"; Destination replyDestination = new Destination() {}; TextMessage reply = mock(TextMessage.class); QueueSender queueSender = mock(QueueSender.class); Session session = mock(Session.class); given(session.createTextMessage(body)).willReturn(reply); given(session.createProducer(replyDestination)).willReturn(queueSender); listener.setDefaultResponseDestination(replyDestination); StubTextMessage inputMessage = createSimpleJmsTextMessage(body); inputMessage.setJMSCorrelationID(correlationId); listener.onMessage(inputMessage, session); assertDefaultListenerMethodInvocation(); verify(reply).setJMSCorrelationID(correlationId); verify(queueSender).send(reply); verify(queueSender).close(); }
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener, String replyDestinationName, boolean pubSubDomain, QosSettings replyQosSettings) throws JMSException { String body = "echo text"; String correlationId = "link-1234"; Destination replyDestination = new Destination() {}; DestinationResolver destinationResolver = mock(DestinationResolver.class); TextMessage reply = mock(TextMessage.class); QueueSender queueSender = mock(QueueSender.class); Session session = mock(Session.class); given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain)) .willReturn(replyDestination); given(session.createTextMessage(body)).willReturn(reply); given(session.createProducer(replyDestination)).willReturn(queueSender); listener.setDestinationResolver(destinationResolver); StubTextMessage inputMessage = createSimpleJmsTextMessage(body); inputMessage.setJMSCorrelationID(correlationId); listener.onMessage(inputMessage, session); verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain); verify(reply).setJMSCorrelationID(correlationId); if (replyQosSettings != null) { verify(queueSender).send(reply, replyQosSettings.getDeliveryMode(), replyQosSettings.getPriority(), replyQosSettings.getTimeToLive()); } else { verify(queueSender).send(reply); } verify(queueSender).close(); }
@Test public void testWithResponsiveMessageDelegateWithDefaultDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception { Queue destination = mock(Queue.class); TextMessage sentTextMessage = mock(TextMessage.class); // correlation ID is queried when response is being created... given(sentTextMessage.getJMSCorrelationID()).willReturn( CORRELATION_ID); // Reply-To is queried when response is being created... given(sentTextMessage.getJMSReplyTo()).willReturn(null); // we want to fall back to the default... TextMessage responseTextMessage = mock(TextMessage.class); QueueSender queueSender = mock(QueueSender.class); Session session = mock(Session.class); given(session.createTextMessage(RESPONSE_TEXT)).willReturn(responseTextMessage); given(session.createProducer(destination)).willReturn(queueSender); ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class); given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT); MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) { @Override protected Object extractMessage(Message message) { return message; } }; adapter.setDefaultResponseDestination(destination); adapter.onMessage(sentTextMessage, session); verify(responseTextMessage).setJMSCorrelationID(CORRELATION_ID); verify(queueSender).send(responseTextMessage); verify(queueSender).close(); verify(delegate).handleMessage(sentTextMessage); }
@Test public void testWithResponsiveMessageDelegateWhenReturnTypeIsAJMSMessageAndNoMessageConverterIsSupplied() throws Exception { Queue destination = mock(Queue.class); final TextMessage sentTextMessage = mock(TextMessage.class); // correlation ID is queried when response is being created... given(sentTextMessage.getJMSCorrelationID()).willReturn(CORRELATION_ID); // Reply-To is queried when response is being created... given(sentTextMessage.getJMSReplyTo()).willReturn(destination); TextMessage responseMessage = mock(TextMessage.class); QueueSender queueSender = mock(QueueSender.class); Session session = mock(Session.class); given(session.createProducer(destination)).willReturn(queueSender); ResponsiveJmsTextMessageReturningMessageDelegate delegate = mock(ResponsiveJmsTextMessageReturningMessageDelegate.class); given(delegate.handleMessage(sentTextMessage)).willReturn(responseMessage); final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) { @Override protected Object extractMessage(Message message) { return message; } }; adapter.setMessageConverter(null); adapter.onMessage(sentTextMessage, session); verify(responseMessage).setJMSCorrelationID(CORRELATION_ID); verify(queueSender).send(responseMessage); verify(queueSender).close(); }
public Message request(Message message) throws JMSException { message.setJMSReplyTo(getTemporaryQueue()); getSender().send(message); return getReceiver().receive(); }
/** * This method called by {@link AppenderBase#doAppend} method to do most * of the real appending work. */ public void append(ILoggingEvent event) { if (!isStarted()) { return; } try { ObjectMessage msg = queueSession.createObjectMessage(); Serializable so = pst.transform(event); msg.setObject(so); queueSender.send(msg); successiveFailureCount = 0; } catch (Exception e) { successiveFailureCount++; if (successiveFailureCount > SUCCESSIVE_FAILURE_LIMIT) { stop(); } addError("Could not send message in JMSQueueAppender [" + name + "].", e); } }
protected void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException { ((QueueSender)m_producer).send((Queue)destination, message, deliveryMode, priority, timeToLive); }
protected void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException { ((QueueSender)m_producer).send((Queue)destination, message, deliveryMode, priority, timeToLive); }
public void sendEvent(BaseTerminalEvent baseDeskEvent) { try { ObjectMessage textMessage = session.createObjectMessage(baseDeskEvent); sender.send(textMessage); } catch (JMSException ex) { System.out.println("Error sending event:" + ex.toString()); } }
protected synchronized void sendMessage(Message message) throws JMSException { if (producer == null && createProducer() == null) { throw new JMSException("Producer for remote queue not available."); } try { producer.send(producerQueue, message); } catch (JMSException e) { producer = null; throw e; } }
protected synchronized void sendMessage(Message message) throws JMSException { if (producer == null && createProducer() == null) { throw new JMSException("Producer for remote queue not available."); } try { producer.send(producerQueue, message); } catch (JMSException e) { producer = null; throw e; } }
@Override void sendMapMessage(Map<String, ?> map, Map properties) throws JMSException { if (map == null) return; MapMessage message = session.createMapMessage(); for (Map.Entry<String, ?> entry : map.entrySet()) message.setObject(entry.getKey(), entry.getValue()); copyHeadersToProperties(properties, message); sender.send(message, getDeliveryMode(), messagePriority, getTimeToLive(properties)); } }
public Message request(Message message) throws JMSException { message.setJMSReplyTo(replyQueue); message.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); requestSender.send(message); return replyReceiver.receive(); }
void sendTextMessage(String text, Map properties) throws JMSException { if (text != null) { TextMessage message = session.createTextMessage(); message.setText(text); copyHeadersToProperties(properties, message); long timeToLive = getTimeToLive(properties); sender.send(message, getDeliveryMode(), messagePriority, timeToLive); } }
@Override public void onMessage(final Message m) { try { Destination queue = m.getJMSReplyTo(); Message m2 = sess.createTextMessage("This is the response"); sender.send(queue, m2); } catch (JMSException e) { log.error(e); } } }