@Test public void testWithQueueConnectionFactoryAndJms11Usage() throws JMSException { QueueConnectionFactory cf = mock(QueueConnectionFactory.class); QueueConnection con = mock(QueueConnection.class); given(cf.createConnection()).willReturn(con); SingleConnectionFactory scf = new SingleConnectionFactory(cf); Connection con1 = scf.createConnection(); Connection con2 = scf.createConnection(); con1.start(); con2.start(); con1.close(); con2.close(); scf.destroy(); // should trigger actual close verify(con).start(); verify(con).stop(); verify(con).close(); verifyNoMoreInteractions(con); }
@Test public void testWithQueueConnectionFactoryAndJms102Usage() throws JMSException { QueueConnectionFactory cf = mock(QueueConnectionFactory.class); QueueConnection con = mock(QueueConnection.class); given(cf.createQueueConnection()).willReturn(con); SingleConnectionFactory scf = new SingleConnectionFactory(cf); Connection con1 = scf.createQueueConnection(); Connection con2 = scf.createQueueConnection(); con1.start(); con2.start(); con1.close(); con2.close(); scf.destroy(); // should trigger actual close verify(con).start(); verify(con).stop(); verify(con).close(); verifyNoMoreInteractions(con); }
public QueueConnection getQueueConnection(QueueConnectionFactory qcf) throws JMSException { final QueueConnection qc; final String username = Config.parms.getString("us"); if (username != null && username.length() != 0) { Log.logger.log(Level.INFO, "getQueueConnection(): authenticating as \"" + username + "\""); final String password = Config.parms.getString("pw"); qc = qcf.createQueueConnection(username, password); } else { qc = qcf.createQueueConnection(); } return qc; }
private void initializeQueue() { Context context = null; try { context = new InitialContext(); final QueueConnectionFactory factory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY_NAME); queueConnection = factory.createQueueConnection(); queueConnection.start(); final Queue queue = (Queue) context.lookup(QUEUE_NAME); session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); sender = session.createSender(queue); sender.setDeliveryMode(DeliveryMode.PERSISTENT); } catch (NamingException | JMSException e) { throw new IWSException(IWSErrors.ERROR, "Queue sender (NotificationEmailSender) initialization failed.", e); } finally { close(context); } }
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(); } }
/** * The method overrides the one in the super class to perform * JMS specific functions. */ @Override protected Object openConnection() throws ConnectionException { qConnection = null; qSession = null; queue = null; try { String server_url = this.getAttributeValueSmart(SERVER_URL); if ("THIS_SERVER".equals(server_url)) server_url = null; String queue_name = this.getQueueName(); JMSServices jmsServices = JMSServices.getInstance(); QueueConnectionFactory qFactory = jmsServices.getQueueConnectionFactory(server_url); qConnection = qFactory.createQueueConnection(); qSession = qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); qConnection.start(); queue = jmsServices.getQueue(qSession, queue_name); } catch (Exception e) { logger.severeException("Exception in JmsAdapter.openConnection()" , e); throw new ConnectionException(ConnectionException.CONNECTION_DOWN, "Exception in invoking JmsAdapter" , e); } return qSession; }
/** * @return the jms queue connection factory */ public QueueConnectionFactory getQueueConnectionFactory(String contextUrl) throws ServiceLocatorException { QueueConnectionFactory factory = (QueueConnectionFactory) queueConnFactoryCache .get(contextUrl == null ? THIS_SERVER : contextUrl); if (factory == null) { try { factory = jmsProvider.getQueueConnectionFactory(namingProvider, contextUrl); if (contextUrl == null) queueConnFactoryCache.put(THIS_SERVER, factory); else queueConnFactoryCache.put(contextUrl, factory); } catch (Exception ex) { throw new ServiceLocatorException(-1, ex.getMessage(), ex); } } return factory; }
/** * 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 fireAndForget(HttpServletRequest request, HttpServletResponse response, String userMessage) { try { InitialContext ctx = new InitialContext(); QueueConnectionFactory qconFactory = (QueueConnectionFactory) ctx.lookup(CONN_FACTORY); try (ConnectionContextFactory ccf = new ConnectionContextFactory(qconFactory)) { ProducerConnectionContext pcc = ccf.createProducerConnectionContext(new Endpoint(Endpoint.Type.QUEUE, QUEUE_NAME)); SimpleBasicMessage msg = new SimpleBasicMessage(userMessage); MessageId mid = new MessageProcessor().send(pcc, msg, FNF_HEADER); PrintWriter out = response.getWriter(); out.println("<h1>Fire and Forget</h1>"); out.println("<p>BasicMessage Sent [" + msg + "]</p>"); out.println("<p>(messageId=" + mid + ")</p>"); } } catch (Exception e) { e.printStackTrace(); } }
protected void rpc(HttpServletRequest request, HttpServletResponse response, String userMessage) { try { InitialContext ctx = new InitialContext(); QueueConnectionFactory qconFactory = (QueueConnectionFactory) ctx.lookup(CONN_FACTORY); ConnectionContextFactory ccf = new ConnectionContextFactory(qconFactory); ProducerConnectionContext pcc = ccf.createProducerConnectionContext(new Endpoint(Endpoint.Type.QUEUE, QUEUE_NAME)); SimpleBasicMessage msg = new SimpleBasicMessage(userMessage); ListenableFuture<BasicMessageWithExtraData<SimpleBasicMessage>> future = new MessageProcessor().sendRPC( pcc, msg, SimpleBasicMessage.class, RPC_HEADER); Futures.addCallback(future, new SimpleFutureCallback()); PrintWriter out = response.getWriter(); out.println("<h1>RPC</h1>"); out.println("<p>BasicMessage Sent [" + msg + "]</p>"); out.println("<p>Check server logs for response.</p>"); } catch (Exception e) { e.printStackTrace(); } }
/** * Inicializa configura��es do recebedor de mensagens JMS * @throws ValidadorException * * @throws NamingException * @throws JMSException */ public void inicializaConsumidorJMS(String proxy, DllDadosDTO configuracaoDll) throws BaseValidadorException { try { if (!isInicializado()) { // seta a configuracao da dll. messageListener.setConfiguracaoDll(configuracaoDll); // recupera initialContext conectado ao ActiveMQ InitialContext initialContext = getInitialContext(proxy); connectionFactory = (QueueConnectionFactory) initialContext.lookup(getJmsConectionFactory()); connection = connectionFactory.createQueueConnection(); session = createQueueSession(connection); aQueue = (Queue) initialContext.lookup(getJmsRequestQueue()); queueReceiver = session.createReceiver(aQueue); queueReceiver.setMessageListener(messageListener); connection.start(); } inicializado = true; } catch (Exception e) { throw new ValidadorException("Erro ao tentar inicializar consumidor JMS!", e); } }
@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"); }
/** * In addition to checking if the connection factory is set, make sure * that the supplied connection factory is of the appropriate type for * the specified destination type: QueueConnectionFactory for queues, * and TopicConnectionFactory for topics. */ public void afterPropertiesSet() { super.afterPropertiesSet(); // Make sure that the ConnectionFactory passed is consistent. // Some provider implementations of the ConnectionFactory interface // implement both domain interfaces under the cover, so just check if // the selected domain is consistent with the type of connection factory. if (isPubSubDomain()) { if (!(getConnectionFactory() instanceof TopicConnectionFactory)) { throw new IllegalArgumentException( "Specified a Spring JMS 1.0.2 transaction manager for topics " + "but did not supply an instance of TopicConnectionFactory"); } } else { if (!(getConnectionFactory() instanceof QueueConnectionFactory)) { throw new IllegalArgumentException( "Specified a Spring JMS 1.0.2 transaction manager for queues " + "but did not supply an instance of QueueConnectionFactory"); } } }
/** * In addition to checking whether the target ConnectionFactory is set, * make sure that the supplied factory is of the appropriate type for * the specified destination type: QueueConnectionFactory for queues, * TopicConnectionFactory for topics. */ public void afterPropertiesSet() { super.afterPropertiesSet(); // Make sure that the ConnectionFactory passed is consistent. // Some provider implementations of the ConnectionFactory interface // implement both domain interfaces under the cover, so just check if // the selected domain is consistent with the type of connection factory. if (isPubSubDomain()) { if (!(getTargetConnectionFactory() instanceof TopicConnectionFactory)) { throw new IllegalArgumentException( "Specified a Spring JMS 1.0.2 SingleConnectionFactory for topics " + "but did not supply an instance of TopicConnectionFactory"); } } else { if (!(getTargetConnectionFactory() instanceof QueueConnectionFactory)) { throw new IllegalArgumentException( "Specified a Spring JMS 1.0.2 SingleConnectionFactory for queues " + "but did not supply an instance of QueueConnectionFactory"); } } }
/** * In addition to checking if the connection factory is set, make sure * that the supplied connection factory is of the appropriate type for * the specified destination type: QueueConnectionFactory for queues, * and TopicConnectionFactory for topics. */ public void afterPropertiesSet() { super.afterPropertiesSet(); // Make sure that the ConnectionFactory passed is consistent. // Some provider implementations of the ConnectionFactory interface // implement both domain interfaces under the cover, so just check if // the selected domain is consistent with the type of connection factory. if (isPubSubDomain()) { if (!(getConnectionFactory() instanceof TopicConnectionFactory)) { throw new IllegalArgumentException( "Specified a Spring JMS 1.0.2 template for topics " + "but did not supply an instance of TopicConnectionFactory"); } } else { if (!(getConnectionFactory() instanceof QueueConnectionFactory)) { throw new IllegalArgumentException( "Specified a Spring JMS 1.0.2 template for queues " + "but did not supply an instance of QueueConnectionFactory"); } } }
@Test @Deprecated public void testTransactionCommit102WithQueue() throws JMSException { QueueConnectionFactory cf = mock(QueueConnectionFactory.class); QueueConnection con = mock(QueueConnection.class); final QueueSession session = mock(QueueSession.class); given(cf.createQueueConnection()).willReturn(con); given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session); JmsTransactionManager tm = new JmsTransactionManager102(cf, false); TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition()); JmsTemplate jt = new JmsTemplate102(cf, false); jt.execute(new SessionCallback() { @Override public Object doInJms(Session sess) { assertTrue(sess == session); return null; } }); tm.commit(ts); verify(session).commit(); verify(session).close(); verify(con).close(); }
@Test public void testWithQueueConnectionFactoryAndJms11Usage() throws JMSException { QueueConnectionFactory cf = mock(QueueConnectionFactory.class); QueueConnection con = mock(QueueConnection.class); given(cf.createConnection()).willReturn(con); SingleConnectionFactory scf = new SingleConnectionFactory(cf); Connection con1 = scf.createConnection(); con1.start(); con1.close(); // should be ignored Connection con2 = scf.createConnection(); con2.start(); con2.close(); // should be ignored scf.destroy(); // should trigger actual close verify(con).start(); verify(con).stop(); verify(con).close(); verifyNoMoreInteractions(con); }
@Test public void testWithQueueConnectionFactoryAndJms102Usage() throws JMSException { QueueConnectionFactory cf = mock(QueueConnectionFactory.class); QueueConnection con = mock(QueueConnection.class); given(cf.createQueueConnection()).willReturn(con); SingleConnectionFactory scf = new SingleConnectionFactory(cf); Connection con1 = scf.createQueueConnection(); con1.start(); con1.close(); // should be ignored Connection con2 = scf.createQueueConnection(); con2.start(); con2.close(); // should be ignored scf.destroy(); // should trigger actual close verify(con).start(); verify(con).stop(); verify(con).close(); verifyNoMoreInteractions(con); }
@Test public void testConnectionFactory102WithQueue() throws JMSException { QueueConnectionFactory cf = mock(QueueConnectionFactory.class); QueueConnection con = mock(QueueConnection.class); given(cf.createQueueConnection()).willReturn(con); SingleConnectionFactory scf = new SingleConnectionFactory102(cf, false); QueueConnection con1 = scf.createQueueConnection(); con1.start(); con1.close(); // should be ignored QueueConnection con2 = scf.createQueueConnection(); con2.start(); con2.close(); // should be ignored scf.destroy(); // should trigger actual close verify(con).start(); verify(con).stop(); verify(con).close(); verifyNoMoreInteractions(con); }
public QueueMessageSender(String jndiFactory, String jndiQueue) throws NamingException, JMSException { // gets the JNDI Context context = new InitialContext(); // gets a ConnectionFactory QueueConnectionFactory queueFactory = (QueueConnectionFactory) context .lookup(jndiFactory); // create a JMS connection from the ConnectionFactory queueConnection = queueFactory.createQueueConnection(); // creates the session with JMS, the first param specifies whether or not the session is transactional // if true the messages only will be send after a commit() queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); // gets the JMS destination queue = (Queue) context.lookup(jndiQueue); // gets the sender to JMS destination queueSender = queueSession.createSender(queue); }
public QueueMessageSender(String jndiFactory, String jndiQueue) throws NamingException, JMSException { // gets the JNDI Context context = new InitialContext(); // gets a ConnectionFactory QueueConnectionFactory queueFactory = (QueueConnectionFactory) context .lookup(jndiFactory); // create a JMS connection from the ConnectionFactory queueConnection = queueFactory.createQueueConnection(); // creates the session with JMS queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); // gets the JMS destination queue = (Queue) context.lookup(jndiQueue); // gets the sender to JMS destination queueSender = queueSession.createSender(queue); }
public static Queue createQueue(String uri, String queueName) throws JMSException { QueueConnectionFactory connectionFactory = null; QueueConnection connection = null; QueueSession session = null; Queue queue = null; try { connectionFactory = new ActiveMQConnectionFactory(uri); connection = connectionFactory.createQueueConnection(); connection.start(); session = connection.createQueueSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE); queue = session.createQueue(queueName); session.commit(); } finally { closeQuietly(session); closeQuietly(connection); } return queue; }
/** * Product message for assigned queue. * * @param uri * e.g.: tcp://3CNL12096:61616 * @param queueName * name of queue * @throws JMSException */ public static void produceTextMsg2Queue(String uri, String queueName, String text) throws JMSException { QueueConnectionFactory connectionFactory = null; QueueConnection connection = null; QueueSession session = null; MessageProducer mp = null; try { connectionFactory = new ActiveMQConnectionFactory(uri); connection = connectionFactory.createQueueConnection(); connection.start(); session = connection.createQueueSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE); mp = session.createProducer(session.createQueue(queueName)); mp.setDeliveryMode(DeliveryMode.PERSISTENT); mp.send(session.createTextMessage(text)); session.commit(); } finally { closeQuietly(mp); closeQuietly(session); closeQuietly(connection); } }
public static String consumeTextMsg4Queue(String uri, String queueName) throws JMSException { QueueConnectionFactory connectionFactory = null; QueueConnection connection = null; QueueSession session = null; TextMessage msg = null; MessageConsumer consumer = null; try { connectionFactory = new ActiveMQConnectionFactory(uri); connection = connectionFactory.createQueueConnection(); connection.start(); session = connection.createQueueSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE); consumer = session.createConsumer(session.createQueue(queueName)); msg = (TextMessage) consumer.receive(); session.commit(); } finally { closeQuietly(consumer); closeQuietly(session); closeQuietly(connection); } if (msg == null) return null; else return msg.getText(); }
/** * Setup the Test * * @throws JMSException * @throws NamingException * * @see junit.framework.TestCase#setUp() */ public void setUp() throws JMSException, NamingException { this.context = getNationalJndiTemplate(); SendToNationalCapabilityImpl impl = new SendToNationalCapabilityImpl(); impl.setJndiTemplate(context); this.sendToNationalCapability = impl; QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) context.lookup(CONNECTION_FACTORY); this.queueConnection = queueConnectionFactory.createQueueConnection(); queueConnection.start(); this.queue = (Queue) context.lookup(DATUP_QUEUE); this.queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); this.receiver = queueSession.createReceiver(queue); }
public void start(){ new Thread(new Runnable() { public void run() { try { QueueConnectionFactory connectionFactory = (QueueConnectionFactory)context.lookup("factory/QueueConnectionFactory"); QueueConnection queueConnection = connectionFactory.createQueueConnection(); QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = queueSession.createQueue(destinationName); QueueReceiver queueReceiver = queueSession.createReceiver(queue); queueReceiver.setMessageListener(MyAsyncReader.this); queueConnection.start(); System.out.println("thred terminated"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); }
protected Connection createConnection() throws JMSException { if (StringUtils.isNotEmpty(authAlias)) { CredentialFactory cf = new CredentialFactory(authAlias,null,null); if (log.isDebugEnabled()) log.debug("using userId ["+cf.getUsername()+"] to create Connection"); if (useJms102()) { if (connectionFactory instanceof QueueConnectionFactory) { return ((QueueConnectionFactory)connectionFactory).createQueueConnection(cf.getUsername(),cf.getPassword()); } else { return ((TopicConnectionFactory)connectionFactory).createTopicConnection(cf.getUsername(),cf.getPassword()); } } else { return connectionFactory.createConnection(cf.getUsername(),cf.getPassword()); } } if (useJms102()) { if (connectionFactory instanceof QueueConnectionFactory) { return ((QueueConnectionFactory)connectionFactory).createQueueConnection(); } else { return ((TopicConnectionFactory)connectionFactory).createTopicConnection(); } } else { return connectionFactory.createConnection(); } }
/** * {@inheritDoc} */ public void submitJob(AbstractFileManagementJob job) { ServiceLocator locator = ServiceLocatorFactory.getLocator(); final QueueConnectionFactory factory = (QueueConnectionFactory) locator.lookup(DEFAULT_QUEUE_CONN_FACTORY); final Queue queue = (Queue) locator.lookup(FileManagementMDB.QUEUE_JNDI_NAME); QueueConnection queueConnection = null; QueueSession queueSession = null; QueueSender queueSender = null; try { queueConnection = factory.createQueueConnection(); queueSession = queueConnection.createQueueSession(true, 0); queueSender = queueSession.createSender(queue); final ObjectMessage message = queueSession.createObjectMessage(job); queueSender.send(message); } catch (JMSException e) { LOG.error("Couldn't submit job to JMS", e); } finally { close(queueSender); close(queueSession); close(queueConnection); } }
@Test(timeout = 60000) public void testInstanceOf() throws Exception { cf = new JmsPoolConnectionFactory(); assertTrue(cf instanceof QueueConnectionFactory); assertTrue(cf instanceof TopicConnectionFactory); cf.stop(); }
@Test(timeout = 60000) public void testInstanceOf() throws Exception { JmsPoolConnectionFactory pcf = new JmsPoolConnectionFactory(); assertTrue(pcf instanceof QueueConnectionFactory); assertTrue(pcf instanceof TopicConnectionFactory); pcf.stop(); }