javax.jms.QueueSender Java Examples
The following examples show how to use
javax.jms.QueueSender.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XAConnectionPoolTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testSenderAndPublisherDest() throws Exception { JmsPoolXAConnectionFactory pcf = createXAPooledConnectionFactory(); QueueConnection connection = pcf.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); QueueSender sender = session.createSender(session.createQueue("AA")); assertNotNull(sender.getQueue().getQueueName()); connection.close(); TopicConnection topicConnection = pcf.createTopicConnection(); TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TopicPublisher topicPublisher = topicSession.createPublisher(topicSession.createTopic("AA")); assertNotNull(topicPublisher.getTopic().getTopicName()); topicConnection.close(); pcf.stop(); }
Example #2
Source File: MethodJmsListenerEndpointTests.java From spring-analysis-note with MIT License | 6 votes |
@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(); }
Example #3
Source File: JmsTypeHeaderInboundEndpointTestCase.java From product-ei with Apache License 2.0 | 6 votes |
/** * Send a message to testInboundQueue queue * * @throws Exception */ private void sendMessage() throws Exception { InitialContext initialContext = JmsClientHelper.getActiveMqInitialContext(); QueueConnectionFactory connectionFactory = (QueueConnectionFactory) initialContext.lookup(JmsClientHelper.QUEUE_CONNECTION_FACTORY); QueueConnection queueConnection = connectionFactory.createQueueConnection(); QueueSession queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); QueueSender sender = queueSession.createSender(queueSession.createQueue(QUEUE_NAME)); String message = "<?xml version='1.0' encoding='UTF-8'?>" + " <ser:getQuote xmlns:ser=\"http://services.samples\" xmlns:xsd=\"http://services.samples/xsd\"> " + " <ser:request>" + " <xsd:symbol>IBM</xsd:symbol>" + " </ser:request>" + " </ser:getQuote>"; try { TextMessage jmsMessage = queueSession.createTextMessage(message); jmsMessage.setJMSType("incorrecttype"); sender.send(jmsMessage); } finally { queueConnection.close(); } }
Example #4
Source File: MethodJmsListenerEndpointTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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(); }
Example #5
Source File: MethodJmsListenerEndpointTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener, boolean pubSubDomain) 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, "replyDestination", 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, "replyDestination", pubSubDomain); verify(reply).setJMSCorrelationID(correlationId); verify(queueSender).send(reply); verify(queueSender).close(); }
Example #6
Source File: MethodJmsListenerEndpointTests.java From java-technology-stack with MIT License | 6 votes |
@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(); }
Example #7
Source File: JmsQueueSenderTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testCreateQueueSender() throws Exception { JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerAmqpConnectionURI()); QueueConnection connection = factory.createQueueConnection(); assertNotNull(connection); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); assertNotNull(session); Queue queue = session.createQueue(name.getMethodName()); QueueSender sender = session.createSender(queue); assertNotNull(sender); QueueViewMBean proxy = getProxyToQueue(name.getMethodName()); assertEquals(0, proxy.getQueueSize()); connection.close(); }
Example #8
Source File: InitConfServer.java From blog with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void onMessage(Message message) { try { TextMessage receiveMessage = (TextMessage) message; String keys = receiveMessage.getText(); LOGGER.info("keys = " + keys); MapMessage returnMess = session.createMapMessage(); returnMess.setStringProperty("/a2/m1", "zhaohui"); returnMess.setStringProperty("/a3/m1/v2", "nanjing"); returnMess.setStringProperty("/a3/m1/v2/t2", "zhaohui"); QueueSender sender = session.createSender((Queue) message.getJMSReplyTo()); sender.send(returnMess); } catch (Exception e) { LOGGER.error("onMessage error", e); } }
Example #9
Source File: QueueSenderTest.java From qpid-broker-j with Apache License 2.0 | 6 votes |
@Test public void anonymousSenderSendToUnknownQueue() throws Exception { QueueConnection connection = ((QueueConnection) getConnectionBuilder().setSyncPublish(true).build()); try { QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue invalidDestination = session.createQueue("unknown"); try { QueueSender sender = session.createSender(null); sender.send(invalidDestination, session.createMessage()); fail("Exception not thrown"); } catch (InvalidDestinationException e) { //PASS } } finally { connection.close(); } }
Example #10
Source File: TracingMessageProducer.java From brave with Apache License 2.0 | 6 votes |
@Override public void send(Queue queue, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException { checkQueueSender(); QueueSender qs = (QueueSender) delegate; Span span = createAndStartProducerSpan(message, destination(message)); SpanInScope ws = tracer.withSpanInScope(span); Throwable error = null; try { qs.send(queue, message, deliveryMode, priority, timeToLive); } catch (Throwable t) { propagateIfFatal(t); error = t; throw t; } finally { if (error != null) span.error(error); span.finish(); ws.close(); } }
Example #11
Source File: SmtpJmsTransportTest.java From javamail with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, TestContextFactory.class.getName()); QueueConnectionFactory queueConnectionFactory = Mockito.mock(QueueConnectionFactory.class); Queue queue = Mockito.mock(Queue.class); Context context = Mockito.mock(Context.class); TestContextFactory.context = context; when(context.lookup(eq("jms/queueConnectionFactory"))).thenReturn(queueConnectionFactory); when(context.lookup(eq("jms/mailQueue"))).thenReturn(queue); queueSender = Mockito.mock(QueueSender.class); QueueConnection queueConnection = Mockito.mock(QueueConnection.class); when(queueConnectionFactory.createQueueConnection()).thenReturn(queueConnection); when(queueConnectionFactory.createQueueConnection(anyString(), anyString())).thenReturn(queueConnection); QueueSession queueSession = Mockito.mock(QueueSession.class); bytesMessage = Mockito.mock(BytesMessage.class); when(queueSession.createBytesMessage()).thenReturn(bytesMessage); when(queueConnection.createQueueSession(anyBoolean(), anyInt())).thenReturn(queueSession); when(queueSession.createSender(eq(queue))).thenReturn(queueSender); transport = new SmtpJmsTransport(Session.getDefaultInstance(new Properties()), new URLName("jms")); transportListener = Mockito.mock(TransportListener.class); transport.addTransportListener(transportListener); }
Example #12
Source File: JmsPoolQueueSenderTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test public void testGetQueue() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); QueueSender sender = session.createSender(queue); assertNotNull(sender.getQueue()); assertSame(queue, sender.getQueue()); sender.close(); try { sender.getQueue(); fail("Cannot read topic on closed sender"); } catch (IllegalStateException ise) {} }
Example #13
Source File: IfsaFacade.java From iaf with Apache License 2.0 | 6 votes |
/** * Intended for server-side reponse sending and implies that the received * message *always* contains a reply-to address. */ public void sendReply(QueueSession session, Message received_message, String response) throws IfsaException { QueueSender tqs=null; try { TextMessage answer = session.createTextMessage(); answer.setText(response); Queue replyQueue = (Queue)received_message.getJMSReplyTo(); tqs = session.createSender(replyQueue ); if (log.isDebugEnabled()) log.debug(getLogPrefix()+ "sending reply to ["+ received_message.getJMSReplyTo()+ "]"); ((IFSAServerQueueSender) tqs).sendReply(received_message, answer); } catch (Throwable t) { throw new IfsaException(t); } finally { if (tqs!=null) { try { tqs.close(); } catch (JMSException e) { log.warn(getLogPrefix()+ "exception closing reply queue sender",e); } } } }
Example #14
Source File: ActiveMQRASession.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Create a queue sender * * @param queue The queue * @return The queue sender * @throws JMSException Thrown if an error occurs */ @Override public QueueSender createSender(final Queue queue) throws JMSException { lock(); try { QueueSession session = getQueueSessionInternal(); if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("createSender " + session + " queue=" + queue); } QueueSender result = session.createSender(queue); result = new ActiveMQRAQueueSender(result, this); if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("createdSender " + session + " sender=" + result); } addProducer(result); return result; } finally { unlock(); } }
Example #15
Source File: ActiveMQSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
void send() throws IOException { try { ActiveMQConn conn = lazyInit.get(); QueueSender sender = conn.sender; BytesMessage bytesMessage = conn.session.createBytesMessage(); bytesMessage.writeBytes(message); sender.send(bytesMessage); } catch (JMSException e) { throw ioException("Unable to send message: ", e); } }
Example #16
Source File: MDDProducer.java From micro-integrator with Apache License 2.0 | 5 votes |
private void sendBytesMessage(String destName, byte[] buffer) throws Exception { InitialContext ic = getInitialContext(); QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) ic.lookup("ConnectionFactory"); QueueConnection connection = queueConnectionFactory.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); BytesMessage bm = session.createBytesMessage(); bm.writeBytes(buffer); QueueSender sender = session.createSender((Queue) ic.lookup(destName)); sender.send(bm); sender.close(); session.close(); connection.close(); }
Example #17
Source File: IfsaFacade.java From iaf with Apache License 2.0 | 5 votes |
protected QueueSender createSender(QueueSession session, Queue queue) throws IfsaException { try { QueueSender queueSender = session.createSender(queue); if (log.isDebugEnabled()) { log.debug(getLogPrefix()+ "got queueSender [" + ToStringBuilder.reflectionToString((IFSAQueueSender) queueSender)+ "]"); } return queueSender; } catch (Exception e) { throw new IfsaException(e); } }
Example #18
Source File: TracingMessageProducer.java From brave with Apache License 2.0 | 5 votes |
TracingMessageProducer(MessageProducer delegate, JmsTracing jmsTracing) { super(jmsTracing.messageProducerExtractor, jmsTracing.messageProducerInjector, jmsTracing); this.delegate = delegate; int types = 0; if (delegate instanceof QueueSender) types |= TYPE_QUEUE; if (delegate instanceof TopicPublisher) types |= TYPE_TOPIC; this.types = types; }
Example #19
Source File: MethodJmsListenerEndpointTests.java From java-technology-stack with MIT License | 5 votes |
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(); }
Example #20
Source File: CachedMessageProducer.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Build a dynamic proxy that reflectively adapts to JMS 2.0 API methods, if necessary. * Otherwise simply return this CachedMessageProducer instance itself. */ public MessageProducer getProxyIfNecessary() { if (completionListenerClass != null) { return (MessageProducer) Proxy.newProxyInstance(CachedMessageProducer.class.getClassLoader(), new Class<?>[] {MessageProducer.class, QueueSender.class, TopicPublisher.class}, new Jms2MessageProducerInvocationHandler()); } else { return this; } }
Example #21
Source File: SimpleOpenWireTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testTempQueueDelete() throws Exception { connection.start(); QueueSession queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); TemporaryQueue tempQueue = queueSession.createTemporaryQueue(); ActiveMQConnection newConn = (ActiveMQConnection) factory.createConnection(); try { QueueSession newQueueSession = newConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); QueueSender queueSender = newQueueSession.createSender(tempQueue); Message msg = queueSession.createMessage(); queueSender.send(msg); try { QueueReceiver consumer = newQueueSession.createReceiver(tempQueue); fail("should have gotten exception but got consumer: " + consumer); } catch (JMSException ex) { //correct } connection.close(); try { Message newMsg = newQueueSession.createMessage(); queueSender.send(newMsg); } catch (JMSException e) { //ok } } finally { newConn.close(); } }
Example #22
Source File: QueueReceiverTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * com.sun.ts.tests.jms.ee.all.queueconn.QueueConnTest line 171 */ @Test public void testCreateReceiverWithMessageSelector() throws Exception { QueueConnection qc = null; try { qc = createQueueConnection(); QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); QueueReceiver qreceiver = qs.createReceiver(queue1, "targetMessage = TRUE"); qc.start(); TextMessage m = qs.createTextMessage(); m.setText("one"); m.setBooleanProperty("targetMessage", false); QueueSender qsender = qs.createSender(queue1); qsender.send(m); m.setText("two"); m.setBooleanProperty("targetMessage", true); qsender.send(m); TextMessage rm = (TextMessage) qreceiver.receive(1000); ProxyAssertSupport.assertEquals("two", rm.getText()); } finally { if (qc != null) { qc.close(); } Thread.sleep(2000); removeAllMessages(queue1.getQueueName(), true); checkEmpty(queue1); } }
Example #23
Source File: ActiveMQRAQueueSender.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Create a new wrapper * * @param producer the producer * @param session the session */ public ActiveMQRAQueueSender(final QueueSender producer, final ActiveMQRASession session) { super(producer, session); if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("constructor(" + producer + ", " + session + ")"); } }
Example #24
Source File: ActiveMQRAQueueSender.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Get queue * * @return The queue * @throws JMSException Thrown if an error occurs */ @Override public Queue getQueue() throws JMSException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("getQueue()"); } return ((QueueSender) producer).getQueue(); }
Example #25
Source File: JmsSession.java From qpid-jms with Apache License 2.0 | 5 votes |
/** * @see javax.jms.QueueSession#createSender(javax.jms.Queue) */ @Override public QueueSender createSender(Queue queue) throws JMSException { checkClosed(); JmsDestination dest = JmsMessageTransformation.transformDestination(connection, queue); JmsQueueSender result = new JmsQueueSender(getNextProducerId(), this, dest); return result; }
Example #26
Source File: JmsQueueSenderTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 10000) public void testMultipleCloseCallsNoErrors() throws Exception { Queue queue = session.createQueue(getTestName()); QueueSender sender = session.createSender(queue); sender.close(); sender.close(); }
Example #27
Source File: JmsQueueSenderTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 10000) public void testSendToQueueWithDeliveryOptsWithNullOnExplicitQueueSenderThrowsInvalidDestinationException() throws Exception { Queue queue = session.createQueue(getTestName()); QueueSender sender = session.createSender(queue); Message message = session.createMessage(); try { sender.send((Queue) null, message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); fail("Expected exception to be thrown"); } catch (InvalidDestinationException ide) { // expected } }
Example #28
Source File: JmsQueueSenderTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 10000) public void testSendToQueueWithNullOnExplicitQueueSender() throws Exception { Queue queue = session.createQueue(getTestName()); QueueSender sender = session.createSender(null); Message message = session.createMessage(); sender.send(queue, message); JmsOutboundMessageDispatch envelope = remotePeer.getLastReceivedMessage(); assertNotNull(envelope); message = envelope.getMessage(); Destination destination = message.getJMSDestination(); assertEquals(queue, destination); }
Example #29
Source File: JmsQueueSenderTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 10000) public void testSendToQueueWithDeliveryOptsWithNullOnExplicitQueueSender() throws Exception { Queue queue = session.createQueue(getTestName()); QueueSender sender = session.createSender(null); Message message = session.createMessage(); sender.send(queue, message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); JmsOutboundMessageDispatch envelope = remotePeer.getLastReceivedMessage(); assertNotNull(envelope); message = envelope.getMessage(); Destination destination = message.getJMSDestination(); assertEquals(queue, destination); }
Example #30
Source File: JmsQueueSenderTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 10000) public void testSendToQueueWithNullOnExplicitQueueSenderThrowsInvalidDestinationException() throws Exception { Queue queue = session.createQueue(getTestName()); QueueSender sender = session.createSender(queue); Message message = session.createMessage(); try { sender.send((Queue) null, message); fail("Expected exception to be thrown"); } catch (InvalidDestinationException ide) { // expected } }