@Test public void testGetQueue() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); QueueReceiver receiver = session.createReceiver(queue); assertNotNull(receiver.getQueue()); assertSame(queue, receiver.getQueue()); receiver.close(); try { receiver.getQueue(); fail("Cannot read topic on closed receiver"); } catch (IllegalStateException ise) {} }
@Test public void testGetTopicSubscriber() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); JmsPoolQueueReceiver receiver = (JmsPoolQueueReceiver) session.createReceiver(queue); assertNotNull(receiver.getQueueReceiver()); assertTrue(receiver.getQueueReceiver() instanceof MockJMSQueueReceiver); receiver.close(); try { receiver.getQueueReceiver(); fail("Cannot read state on closed receiver"); } catch (IllegalStateException ise) {} }
private void doTestCreateQueueSender(boolean useAnonymousProducers) throws JMSException { cf.setUseAnonymousProducers(useAnonymousProducers); JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue1 = session.createTemporaryQueue(); Queue queue2 = session.createTemporaryQueue(); JmsPoolQueueSender sender1 = (JmsPoolQueueSender) session.createSender(queue1); JmsPoolQueueSender sender2 = (JmsPoolQueueSender) session.createSender(queue2); if (useAnonymousProducers) { assertSame(sender1.getMessageProducer(), sender2.getMessageProducer()); } else { assertNotSame(sender1.getMessageProducer(), sender2.getMessageProducer()); } connection.close(); }
@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) {} }
@Test public void testGetTopicSubscriber() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); JmsPoolQueueSender sender = (JmsPoolQueueSender) session.createSender(queue); assertNotNull(sender.getQueueSender()); assertTrue(sender.getQueueSender() instanceof MockJMSQueueSender); sender.close(); try { sender.getQueueSender(); fail("Cannot read state on closed sender"); } catch (IllegalStateException ise) {} }
@Test public void testGetQueue() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); QueueBrowser browser = session.createBrowser(queue); assertNotNull(browser.getQueue()); browser.close(); browser.close(); try { browser.getQueue(); fail("Should not be able to use a closed browser"); } catch (IllegalStateException ise) { } }
@Test public void testGetQueueBrowser() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); JmsPoolQueueBrowser browser = (JmsPoolQueueBrowser) session.createBrowser(queue); assertNotNull(browser.getQueueBrowser()); browser.close(); try { browser.getQueueBrowser(); fail("Should not be able to use a closed browser"); } catch (IllegalStateException ise) { } }
@Test public void testGetMessageSelector() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); QueueBrowser browser = session.createBrowser(queue, "color = red"); assertNotNull(browser.getMessageSelector()); assertEquals("color = red", browser.getMessageSelector()); browser.close(); try { browser.getMessageSelector(); fail("Should not be able to use a closed browser"); } catch (IllegalStateException ise) { } }
@Test public void testGetEnumeration() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); QueueBrowser browser = session.createBrowser(queue); assertNotNull(browser.getEnumeration()); browser.close(); try { browser.getEnumeration(); fail("Should not be able to use a closed browser"); } catch (IllegalStateException ise) { } }
@Test(timeout = 60000) public void testSenderAndPublisherDest() throws Exception { JmsPoolXAConnectionFactory pcf = new JmsPoolXAConnectionFactory(); pcf.setConnectionFactory(new ActiveMQXAConnectionFactory( "vm://test?broker.persistent=false&broker.useJmx=false")); 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(); }
public static ManagedSession create( Session session ) { if ( (session instanceof XAQueueSession) && (session instanceof XATopicSession)) return new ManagedXAQueueTopicSession(session); if (session instanceof XAQueueSession) return new ManagedXAQueueSession((XAQueueSession) session); if (session instanceof XATopicSession) return new ManagedXATopicSession((XATopicSession) session); if ( (session instanceof QueueSession) && (session instanceof TopicSession)) return new ManagedQueueTopicSession(session); if (session instanceof QueueSession) return new ManagedQueueSession((QueueSession) session); if (session instanceof TopicSession) return new ManagedTopicSession((TopicSession) session); return new ManagedSession(session); }
/** Send a JSON message to our notification queue. */ public void invokeJMS(JsonObject json) throws JMSException, NamingException { if (!initialized) initialize(); //gets our JMS managed resources (Q and QCF) QueueConnection connection = queueCF.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); TextMessage message = session.createTextMessage(json.toString()); System.out.println("Sending "+json.toString()+" to "+queue.getQueueName()); QueueSender sender = session.createSender(queue); sender.send(message); sender.close(); session.close(); connection.close(); System.out.println("Message sent successfully!"); }
/** * Sends a message to the myWMS application inside the application * server. * * @param mfcMessage the message to be send * @throws JMSException * @throws NamingException */ public void send(MFCMessage mfcMessage) throws JMSException, NamingException { // create the jms session QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); // lookup of the jms queue over jndi Queue outputQueue = (Queue) context.lookup("queue/" + OUTPUT_QUEUE_NAME); // create the message publisher QueueSender sender = session.createSender(outputQueue); ObjectMessage objectMessage = session.createObjectMessage(); objectMessage.setObject(mfcMessage); objectMessage.setJMSTimestamp(System.currentTimeMillis()); sender.send(objectMessage); sender.close(); session.close(); }
private void acknowledge(Message jmsMessage, String msgid) throws JMSException, ServiceLocatorException { QueueConnection connection = null; QueueSession session = null; QueueSender sender = null; try { Queue respQueue = (Queue) jmsMessage.getJMSReplyTo(); QueueConnectionFactory qcf = JMSServices.getInstance().getQueueConnectionFactory(null); connection = qcf.createQueueConnection(); session = connection.createQueueSession(false, QueueSession.DUPS_OK_ACKNOWLEDGE); sender = session.createSender(respQueue); Message respMsg = session.createTextMessage(msgid); // respMsg.setJMSCorrelationID(correlationId); not used sender.send(respMsg); } finally { if (sender != null) sender.close(); if (session != null) session.close(); if (connection != null) connection.close(); } }
/** * 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(); } }
public ReorderRequestMessageListener() { try { Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF); properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(USERNAME, PASSWORD)); properties.put(QUEUE_NAME_PREFIX + REORDER_REQUEST_QUEUE, REORDER_REQUEST_QUEUE); InitialContext ctx = new InitialContext(properties); // Lookup connection factory QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME); QueueConnection queueConnection = connFactory.createQueueConnection(); queueConnection.start(); QueueSession queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); //Receive message Queue queue = (Queue) ctx.lookup(REORDER_REQUEST_QUEUE); MessageConsumer consumer = queueSession.createConsumer(queue); consumer.setMessageListener(this); } catch (NamingException | JMSException e) { e.printStackTrace(); } }
public ReorderResponseMessageListener() { try { Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF); properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(USERNAME, PASSWORD)); properties.put("queue."+ REORDER_RESPONSE_QUEUE, REORDER_RESPONSE_QUEUE); InitialContext ctx = new InitialContext(properties); // Lookup connection factory QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME); queueConnection = connFactory.createQueueConnection(); queueConnection.start(); queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); //Receive message Queue queue = (Queue) ctx.lookup(REORDER_RESPONSE_QUEUE); MessageConsumer consumer = queueSession.createConsumer(queue); consumer.setMessageListener(this); } catch (NamingException | JMSException e) { e.printStackTrace(); } }
public static void sendMessage(Order order) throws NamingException, JMSException { Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF); properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(USERNAME, PASSWORD)); properties.put(QUEUE_NAME_PREFIX + REORDER_REQUEST_QUEUE, REORDER_REQUEST_QUEUE); InitialContext ctx = new InitialContext(properties); // Lookup connection factory QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME); queueConnection = connFactory.createQueueConnection(); queueConnection.start(); queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); // Send message Queue queue = (Queue) ctx.lookup(REORDER_REQUEST_QUEUE); // create the message to send ObjectMessage message = queueSession.createObjectMessage(order); javax.jms.QueueSender queueSender = queueSession.createSender(queue); queueSender.send(message); queueSender.close(); queueSession.close(); queueConnection.close(); }
public void setupJMS() throws NamingException, JMSException { InitialContext iniCtx; if (this.isClustered()) { Logger.getLogger(getClass().getName()).log(Level.INFO, "Clustered - Using HA-JMS"); Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces"); p.put(Context.PROVIDER_URL, "localhost:1100"); // HA-JNDI port. iniCtx = new InitialContext(p); } else { Logger.getLogger(getClass().getName()).log(Level.INFO, "Not clustered - Using non-HA JMS"); iniCtx = new InitialContext(); } QueueConnectionFactory qcf = (QueueConnectionFactory) iniCtx.lookup("ConnectionFactory"); queue = (javax.jms.Queue) iniCtx.lookup("queue/acsQueue"); conn = qcf.createQueueConnection(); conn.setExceptionListener(this); conn.start(); queuesession = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); producer = queuesession.createProducer(queue); clear(); }
protected void initializeInboundDestinationBridgesOutboundSide(QueueConnection connection) throws JMSException { if (inboundQueueBridges != null) { QueueSession outboundSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); for (InboundQueueBridge bridge : inboundQueueBridges) { String queueName = bridge.getInboundQueueName(); Queue foreignQueue = createForeignQueue(outboundSession, queueName); bridge.setConsumer(null); bridge.setConsumerQueue(foreignQueue); bridge.setConsumerConnection(connection); bridge.setJmsConnector(this); addInboundBridge(bridge); } outboundSession.close(); } }
protected void initializeInboundDestinationBridgesLocalSide(QueueConnection connection) throws JMSException { if (inboundQueueBridges != null) { QueueSession localSession = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE); for (InboundQueueBridge bridge : inboundQueueBridges) { String localQueueName = bridge.getLocalQueueName(); Queue activemqQueue = createActiveMQQueue(localSession, localQueueName); bridge.setProducerQueue(activemqQueue); bridge.setProducerConnection(connection); if (bridge.getJmsMessageConvertor() == null) { bridge.setJmsMessageConvertor(getInboundMessageConvertor()); } bridge.setJmsConnector(this); addInboundBridge(bridge); } localSession.close(); } }
protected void initializeOutboundDestinationBridgesOutboundSide(QueueConnection connection) throws JMSException { if (outboundQueueBridges != null) { QueueSession outboundSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); for (OutboundQueueBridge bridge : outboundQueueBridges) { String queueName = bridge.getOutboundQueueName(); Queue foreignQueue = createForeignQueue(outboundSession, queueName); bridge.setProducerQueue(foreignQueue); bridge.setProducerConnection(connection); if (bridge.getJmsMessageConvertor() == null) { bridge.setJmsMessageConvertor(getOutboundMessageConvertor()); } bridge.setJmsConnector(this); addOutboundBridge(bridge); } outboundSession.close(); } }
protected void initializeOutboundDestinationBridgesLocalSide(QueueConnection connection) throws JMSException { if (outboundQueueBridges != null) { QueueSession localSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); for (OutboundQueueBridge bridge : outboundQueueBridges) { String localQueueName = bridge.getLocalQueueName(); Queue activemqQueue = createActiveMQQueue(localSession, localQueueName); bridge.setConsumer(null); bridge.setConsumerQueue(activemqQueue); bridge.setConsumerConnection(connection); bridge.setJmsConnector(this); addOutboundBridge(bridge); } localSession.close(); } }
/** * Create {@link MessageProducer} instance for the provided session. * * @param session JMS Session instance. * @return Message producer. * @throws JMSConnectorException Error when creating the JMS Message Producer. */ public MessageProducer createMessageProducer(Session session) throws JMSConnectorException { try { if (logger.isDebugEnabled()) { logger.debug("Creating a new JMS Message Producer on: " + this.connectionFactoryString); } if ((JMSConstants.JMS_SPEC_VERSION_1_1.equals(jmsSpec)) || (JMSConstants.JMS_SPEC_VERSION_2_0 .equals(jmsSpec))) { return session.createProducer(null); } else { if (JMSConstants.JMSDestinationType.QUEUE.equals(this.destinationType)) { return ((QueueSession) session).createSender(null); } else { return ((TopicSession) session).createPublisher(null); } } } catch (JMSException e) { throw new JMSConnectorException("JMS Exception while creating the producer for the destination ", e); } }
/** * Close a JMS {@link Session}. * @param session Session that needs to be closed. * @throws JMSException if an error occurs while closing the session. */ public void closeSession(Session session) throws JMSException { if (session != null) { if (logger.isDebugEnabled()) { logger.debug("Closing a JMS Session of: " + this.connectionFactoryString); } if ((JMSConstants.JMS_SPEC_VERSION_1_1.equals(jmsSpec)) || (JMSConstants.JMS_SPEC_VERSION_2_0 .equals(jmsSpec))) { session.close(); } else { if (JMSConstants.JMSDestinationType.QUEUE.equals(this.destinationType)) { ((QueueSession) session).close(); } else { ((TopicSession) session).close(); } } } }
/** * To publish the messages to a queue. * * @throws JMSException JMS Exception. * @throws InterruptedException Interrupted exception while waiting in between messages. */ public void publishMessagesToQueue(String queueName) throws JMSException, InterruptedException { QueueConnection queueConn = (QueueConnection) connectionFactory.createConnection(); queueConn.start(); QueueSession queueSession = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = queueSession.createQueue(queueName); MessageProducer queueSender = queueSession.createProducer(destination); queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT); for (int index = 0; index < 10; index++) { String queueText = "Queue Message : " + (index + 1); TextMessage queueMessage = queueSession.createTextMessage(queueText); queueSender.send(queueMessage); Thread.sleep(1000); logger.info("Publishing " + queueText + " to queue " + queueName); } queueConn.close(); queueSession.close(); queueSender.close(); }
/** * To receive a message from a queue. * * @throws JMSException JMS Exception. * @throws InterruptedException Interrupted exception while waiting in between messages. */ public void receiveMessagesFromQueue() throws JMSException, InterruptedException { QueueConnection queueConn = (QueueConnection) connectionFactory.createConnection(); QueueSession queueSession = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = queueSession.createQueue(JMSTestConstants.QUEUE_NAME_1); MessageConsumer queueReceiver = queueSession.createConsumer(destination); MessageListener listener = message -> { try { if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; logger.info("Message text received : " + (textMessage.getText())); } } catch (JMSException e) { logger.info("JMS exception occurred."); } }; queueReceiver.setMessageListener(listener); queueConn.start(); }
@Test public void testConnectionCredentialsFail() throws Exception { resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); QueueConnection queueConnection = qraConnectionFactory.createQueueConnection(); QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); ManagedConnection mc = ((ActiveMQRASession) session).getManagedConnection(); queueConnection.close(); mc.destroy(); try { queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testwrongpassword"); queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE).close(); fail("should throw esxception"); } catch (JMSException e) { //pass } }
@Override protected void setUp() throws Exception { super.setUp(); context = createApplicationContext(); createConnections(); requestServerSession = localConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue theQueue = requestServerSession.createQueue(getClass().getName()); requestServerConsumer = requestServerSession.createConsumer(theQueue); requestServerConsumer.setMessageListener(this); requestServerProducer = requestServerSession.createProducer(null); QueueSession session = remoteConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); requestor = new QueueRequestor(session, theQueue); }
@Override protected void setUp() throws Exception { super.setUp(); context = createApplicationContext(); createConnections(); requestServerSession = localConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); theQueue = requestServerSession.createQueue(QUEUE_NAME); requestServerConsumer = requestServerSession.createConsumer(theQueue); requestServerProducer = requestServerSession.createProducer(null); QueueSession session = localConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); requestor = new QueueRequestor(session, theQueue); }
/** * 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); } }
/** * Create a queue receiver * * @param queue The queue * @return The queue receiver * @throws JMSException Thrown if an error occurs */ @Override public QueueReceiver createReceiver(final Queue queue) throws JMSException { lock(); try { QueueSession session = getQueueSessionInternal(); if (ActiveMQRASession.trace) { ActiveMQRALogger.LOGGER.trace("createReceiver " + session + " queue=" + queue); } QueueReceiver result = session.createReceiver(queue); result = new ActiveMQRAQueueReceiver(result, this); if (ActiveMQRASession.trace) { ActiveMQRALogger.LOGGER.trace("createdReceiver " + session + " receiver=" + result); } addConsumer(result); return result; } finally { unlock(); } }
/** * Create a queue receiver * * @param queue The queue * @param messageSelector * @return The queue receiver * @throws JMSException Thrown if an error occurs */ @Override public QueueReceiver createReceiver(final Queue queue, final String messageSelector) throws JMSException { lock(); try { QueueSession session = getQueueSessionInternal(); if (ActiveMQRASession.trace) { ActiveMQRALogger.LOGGER.trace("createReceiver " + session + " queue=" + queue + " selector=" + messageSelector); } QueueReceiver result = session.createReceiver(queue, messageSelector); result = new ActiveMQRAQueueReceiver(result, this); if (ActiveMQRASession.trace) { ActiveMQRALogger.LOGGER.trace("createdReceiver " + session + " receiver=" + result); } addConsumer(result); return result; } finally { unlock(); } }
/** * 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 (ActiveMQRASession.trace) { ActiveMQRALogger.LOGGER.trace("createSender " + session + " queue=" + queue); } QueueSender result = session.createSender(queue); result = new ActiveMQRAQueueSender(result, this); if (ActiveMQRASession.trace) { ActiveMQRALogger.LOGGER.trace("createdSender " + session + " sender=" + result); } addProducer(result); return result; } finally { unlock(); } }
/** * Get the queue session * * @return The queue session * @throws JMSException Thrown if an error occurs */ @Override public QueueSession getQueueSession() throws JMSException { if (ActiveMQRASession.trace) { ActiveMQRALogger.LOGGER.trace("getQueueSession()"); } if (cri.getType() == ActiveMQRAConnectionFactory.CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.QUEUE_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.TOPIC_CONNECTION) { throw new IllegalStateException("Non XA connection"); } lock(); try { return this; } finally { unlock(); } }
@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); }
public void setupConnection() throws JMSException, NamingException { Properties properties1 = new Properties(); properties1.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); properties1.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); properties1.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099"); InitialContext iniCtx = new InitialContext(properties1); Object tmp = iniCtx.lookup("ConnectionFactory"); QueueConnectionFactory qcf = (QueueConnectionFactory) tmp; conn = qcf.createQueueConnection(); que = (Queue) iniCtx.lookup("queue/questionqueue"); session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); conn.start(); System.out.println("Connection Started"); }
/** * Overrides the superclass method to use the JMS 1.0.2 API to send a response. * <p>Uses the JMS pub-sub API if the given destination is a topic, * else uses the JMS queue API. */ protected void sendResponse(Session session, Destination destination, Message response) throws JMSException { MessageProducer producer = null; try { if (destination instanceof Topic) { producer = ((TopicSession) session).createPublisher((Topic) destination); postProcessProducer(producer, response); ((TopicPublisher) producer).publish(response); } else { producer = ((QueueSession) session).createSender((Queue) destination); postProcessProducer(producer, response); ((QueueSender) producer).send(response); } } finally { JmsUtils.closeMessageProducer(producer); } }
/** * This implementation overrides the superclass method to use JMS 1.0.2 API. */ protected MessageConsumer createConsumer(Session session, Destination destination) throws JMSException { if (isPubSubDomain()) { if (isSubscriptionDurable()) { return ((TopicSession) session).createDurableSubscriber( (Topic) destination, getDurableSubscriptionName(), getMessageSelector(), isPubSubNoLocal()); } else { return ((TopicSession) session).createSubscriber( (Topic) destination, getMessageSelector(), isPubSubNoLocal()); } } else { return ((QueueSession) session).createReceiver((Queue) destination, getMessageSelector()); } }