javax.jms.TopicConnection Java Examples
The following examples show how to use
javax.jms.TopicConnection.
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: SingleConnectionFactory.java From spring-analysis-note with MIT License | 6 votes |
/** * Create a default Session for this ConnectionFactory, * adapting to JMS 1.0.2 style queue/topic mode if necessary. * @param con the JMS Connection to operate on * @param mode the Session acknowledgement mode * ({@code Session.TRANSACTED} or one of the common modes) * @return the newly created Session * @throws JMSException if thrown by the JMS API */ protected Session createSession(Connection con, Integer mode) throws JMSException { // Determine JMS API arguments... boolean transacted = (mode == Session.SESSION_TRANSACTED); int ackMode = (transacted ? Session.AUTO_ACKNOWLEDGE : mode); // Now actually call the appropriate JMS factory method... if (Boolean.FALSE.equals(this.pubSubMode) && con instanceof QueueConnection) { return ((QueueConnection) con).createQueueSession(transacted, ackMode); } else if (Boolean.TRUE.equals(this.pubSubMode) && con instanceof TopicConnection) { return ((TopicConnection) con).createTopicSession(transacted, ackMode); } else { return con.createSession(transacted, ackMode); } }
Example #2
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 #3
Source File: ManagedConnection.java From ats-framework with Apache License 2.0 | 6 votes |
public static ManagedConnection create( final Connection connection ) { if ( (connection instanceof XAQueueConnection) && (connection instanceof XATopicConnection)) { return new ManagedXAQueueTopicConnection(connection); } else if (connection instanceof XAQueueConnection) { return new ManagedXAQueueConnection((XAQueueConnection) connection); } else if (connection instanceof XATopicConnection) { return new ManagedXATopicConnection((XATopicConnection) connection); } else if ( (connection instanceof QueueConnection) && (connection instanceof TopicConnection)) { return new ManagedQueueTopicConnection(connection); } else if (connection instanceof QueueConnection) { return new ManagedQueueConnection((QueueConnection) connection); } else if (connection instanceof TopicConnection) { return new ManagedTopicConnection((TopicConnection) connection); } else { return new ManagedConnection(connection); } }
Example #4
Source File: PooledConnectionTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testTopicMessageSend() throws Exception { cf.setMaxConnections(1); TopicConnection connection = cf.createTopicConnection(); try { TopicSession topicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = topicSession.createTopic(getTestName()); TopicPublisher topicPublisher = topicSession.createPublisher(topic); topicPublisher.send(topicSession.createMessage()); assertEquals(1, cf.getNumConnections()); } finally { connection.close(); cf.stop(); } }
Example #5
Source File: SingleConnectionFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testWithTopicConnectionFactoryAndJms102Usage() throws JMSException { TopicConnectionFactory cf = mock(TopicConnectionFactory.class); TopicConnection con = mock(TopicConnection.class); given(cf.createTopicConnection()).willReturn(con); SingleConnectionFactory scf = new SingleConnectionFactory(cf); Connection con1 = scf.createTopicConnection(); Connection con2 = scf.createTopicConnection(); 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); }
Example #6
Source File: SingleConnectionFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testWithTopicConnectionFactoryAndJms11Usage() throws JMSException { TopicConnectionFactory cf = mock(TopicConnectionFactory.class); TopicConnection con = mock(TopicConnection.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); }
Example #7
Source File: SingleConnectionFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testWithTopicConnection() throws JMSException { Connection con = mock(TopicConnection.class); SingleConnectionFactory scf = new SingleConnectionFactory(con); TopicConnection con1 = scf.createTopicConnection(); con1.start(); con1.stop(); con1.close(); TopicConnection con2 = scf.createTopicConnection(); con2.start(); con2.stop(); con2.close(); scf.destroy(); // should trigger actual close verify(con, times(2)).start(); verify(con, times(2)).stop(); verify(con).close(); verifyNoMoreInteractions(con); }
Example #8
Source File: UserCredentialsConnectionFactoryAdapter.java From spring-analysis-note with MIT License | 6 votes |
/** * This implementation delegates to the {@code createTopicConnection(username, password)} * method of the target TopicConnectionFactory, passing in the specified user credentials. * If the specified username is empty, it will simply delegate to the standard * {@code createTopicConnection()} method of the target ConnectionFactory. * @param username the username to use * @param password the password to use * @return the Connection * @see javax.jms.TopicConnectionFactory#createTopicConnection(String, String) * @see javax.jms.TopicConnectionFactory#createTopicConnection() */ protected TopicConnection doCreateTopicConnection( @Nullable String username, @Nullable String password) throws JMSException { ConnectionFactory target = obtainTargetConnectionFactory(); if (!(target instanceof TopicConnectionFactory)) { throw new javax.jms.IllegalStateException("'targetConnectionFactory' is not a TopicConnectionFactory"); } TopicConnectionFactory queueFactory = (TopicConnectionFactory) target; if (StringUtils.hasLength(username)) { return queueFactory.createTopicConnection(username, password); } else { return queueFactory.createTopicConnection(); } }
Example #9
Source File: JMSSample.java From WeEvent with Apache License 2.0 | 6 votes |
private static void publish() throws JMSException { // get topic connection TopicConnectionFactory connectionFactory = new WeEventConnectionFactory(defaultBrokerUrl); TopicConnection connection = connectionFactory.createTopicConnection(); // start connection connection.start(); // create session TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); // create topic Topic topic = session.createTopic(topicName); // create publisher TopicPublisher publisher = session.createPublisher(topic); // send message BytesMessage msg = session.createBytesMessage(); msg.writeBytes(("hello WeEvent").getBytes(StandardCharsets.UTF_8)); publisher.publish(msg); System.out.print("send done."); connection.close(); }
Example #10
Source File: SimpleOpenWireTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testNotificationProperties() throws Exception { try (TopicConnection topicConnection = factory.createTopicConnection()) { TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic notificationsTopic = topicSession.createTopic("activemq.notifications"); TopicSubscriber subscriber = topicSession.createSubscriber(notificationsTopic); List<Message> receivedMessages = new CopyOnWriteArrayList<>(); subscriber.setMessageListener(receivedMessages::add); topicConnection.start(); Wait.waitFor(() -> receivedMessages.size() > 0); Assert.assertTrue(receivedMessages.size() > 0); for (Message message : receivedMessages) { assertNotNull(message); assertNotNull(message.getStringProperty("_AMQ_NotifType")); } } }
Example #11
Source File: SingleConnectionFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testWithTopicConnectionFactoryAndJms102Usage() throws JMSException { TopicConnectionFactory cf = mock(TopicConnectionFactory.class); TopicConnection con = mock(TopicConnection.class); given(cf.createTopicConnection()).willReturn(con); SingleConnectionFactory scf = new SingleConnectionFactory(cf); Connection con1 = scf.createTopicConnection(); Connection con2 = scf.createTopicConnection(); 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); }
Example #12
Source File: JmsConnectionFactory.java From qpid-jms with Apache License 2.0 | 6 votes |
@Override public TopicConnection createTopicConnection(String username, String password) throws JMSException { JmsTopicConnection connection = null; try { JmsConnectionInfo connectionInfo = configureConnectionInfo(username, password); Provider provider = createProvider(remoteURI); connection = new JmsTopicConnection(connectionInfo, provider); connection.setExceptionListener(exceptionListener); connection.connect(); } catch (Exception e) { if (connection != null) { try { connection.close(); } catch (Throwable ignored) {} } throw JmsExceptionSupport.create(e); } return connection; }
Example #13
Source File: SingleConnectionFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testWithTopicConnection() throws JMSException { Connection con = mock(TopicConnection.class); SingleConnectionFactory scf = new SingleConnectionFactory(con); TopicConnection con1 = scf.createTopicConnection(); con1.start(); con1.stop(); con1.close(); TopicConnection con2 = scf.createTopicConnection(); con2.start(); con2.stop(); con2.close(); scf.destroy(); // should trigger actual close verify(con, times(2)).start(); verify(con, times(2)).stop(); verify(con).close(); verifyNoMoreInteractions(con); }
Example #14
Source File: UserCredentialsConnectionFactoryAdapter.java From java-technology-stack with MIT License | 6 votes |
/** * This implementation delegates to the {@code createTopicConnection(username, password)} * method of the target TopicConnectionFactory, passing in the specified user credentials. * If the specified username is empty, it will simply delegate to the standard * {@code createTopicConnection()} method of the target ConnectionFactory. * @param username the username to use * @param password the password to use * @return the Connection * @see javax.jms.TopicConnectionFactory#createTopicConnection(String, String) * @see javax.jms.TopicConnectionFactory#createTopicConnection() */ protected TopicConnection doCreateTopicConnection( @Nullable String username, @Nullable String password) throws JMSException { ConnectionFactory target = obtainTargetConnectionFactory(); if (!(target instanceof TopicConnectionFactory)) { throw new javax.jms.IllegalStateException("'targetConnectionFactory' is not a TopicConnectionFactory"); } TopicConnectionFactory queueFactory = (TopicConnectionFactory) target; if (StringUtils.hasLength(username)) { return queueFactory.createTopicConnection(username, password); } else { return queueFactory.createTopicConnection(); } }
Example #15
Source File: SingleConnectionFactory.java From java-technology-stack with MIT License | 6 votes |
/** * Create a default Session for this ConnectionFactory, * adapting to JMS 1.0.2 style queue/topic mode if necessary. * @param con the JMS Connection to operate on * @param mode the Session acknowledgement mode * ({@code Session.TRANSACTED} or one of the common modes) * @return the newly created Session * @throws JMSException if thrown by the JMS API */ protected Session createSession(Connection con, Integer mode) throws JMSException { // Determine JMS API arguments... boolean transacted = (mode == Session.SESSION_TRANSACTED); int ackMode = (transacted ? Session.AUTO_ACKNOWLEDGE : mode); // Now actually call the appropriate JMS factory method... if (Boolean.FALSE.equals(this.pubSubMode) && con instanceof QueueConnection) { return ((QueueConnection) con).createQueueSession(transacted, ackMode); } else if (Boolean.TRUE.equals(this.pubSubMode) && con instanceof TopicConnection) { return ((TopicConnection) con).createTopicSession(transacted, ackMode); } else { return con.createSession(transacted, ackMode); } }
Example #16
Source File: SingleConnectionFactory.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Create a default Session for this ConnectionFactory, * adapting to JMS 1.0.2 style queue/topic mode if necessary. * @param con the JMS Connection to operate on * @param mode the Session acknowledgement mode * ({@code Session.TRANSACTED} or one of the common modes) * @return the newly created Session * @throws JMSException if thrown by the JMS API */ protected Session createSession(Connection con, Integer mode) throws JMSException { // Determine JMS API arguments... boolean transacted = (mode == Session.SESSION_TRANSACTED); int ackMode = (transacted ? Session.AUTO_ACKNOWLEDGE : mode); // Now actually call the appropriate JMS factory method... if (Boolean.FALSE.equals(this.pubSubMode) && con instanceof QueueConnection) { return ((QueueConnection) con).createQueueSession(transacted, ackMode); } else if (Boolean.TRUE.equals(this.pubSubMode) && con instanceof TopicConnection) { return ((TopicConnection) con).createTopicSession(transacted, ackMode); } else { return con.createSession(transacted, ackMode); } }
Example #17
Source File: TopicSessionTest.java From qpid-broker-j with Apache License 2.0 | 6 votes |
@Test public void testTopicSessionCannotCreateQueues() throws Exception { TopicConnection topicConnection = getTopicConnection(); try { TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topicSession.createQueue("abc"); fail("Expected exception was not thrown"); } catch (javax.jms.IllegalStateException s) { // PASS } finally { topicConnection.close(); } }
Example #18
Source File: TopicSessionTest.java From qpid-broker-j with Apache License 2.0 | 6 votes |
@Test public void testTopicSessionCannotCreateTemporaryQueues() throws Exception { TopicConnection topicConnection = getTopicConnection(); try { TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topicSession.createTemporaryQueue(); fail("Expected exception was not thrown"); } catch (javax.jms.IllegalStateException s) { // PASS } finally { topicConnection.close(); } }
Example #19
Source File: JMSConnectionFactory.java From micro-integrator with Apache License 2.0 | 6 votes |
protected Session createSession(Connection connection) { try { if (JMSConstants.JMS_SPEC_VERSION_1_1.equals(jmsSpec) || JMSConstants.JMS_SPEC_VERSION_2_0 .equals(jmsSpec)) { return connection.createSession(transactedSession, sessionAckMode); } else { if (this.destinationType.equals(JMSConstants.JMSDestinationType.QUEUE)) { return (QueueSession) ((QueueConnection) (connection)) .createQueueSession(transactedSession, sessionAckMode); } else if (this.destinationType.equals(JMSConstants.JMSDestinationType.TOPIC)) { return (TopicSession) ((TopicConnection) (connection)) .createTopicSession(transactedSession, sessionAckMode); } } } catch (JMSException e) { logger.error("JMS Exception while obtaining session for factory '" + this.connectionFactoryString + "' " + e .getMessage(), e); } return null; }
Example #20
Source File: ConnectionFactoryTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Test that ConnectionFactory can be cast to TopicConnectionFactory and TopicConnection can be * created. */ @Test public void testTopicConnectionFactory() throws Exception { deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC_XA_FALSE", "/CF_TOPIC_XA_FALSE"); TopicConnectionFactory qcf = (TopicConnectionFactory) ic.lookup("/CF_TOPIC_XA_FALSE"); TopicConnection tc = qcf.createTopicConnection(); tc.close(); undeployConnectionFactory("CF_TOPIC_XA_FALSE"); }
Example #21
Source File: AuthenticationTest.java From ballerina-message-broker with Apache License 2.0 | 5 votes |
@Parameters({ "broker-port", "admin-username", "admin-password" }) @Test(description = "Test user with valid credentials") public void testValidClientConnection(String port, String adminUsername, String adminPassword) throws Exception { String topicName = "MyTopic1"; InitialContext initialContext = ClientHelper .getInitialContextBuilder(adminUsername, adminPassword, "localhost", port).withTopic(topicName).build(); TopicConnectionFactory connectionFactory = (TopicConnectionFactory) initialContext .lookup(ClientHelper.CONNECTION_FACTORY); TopicConnection connection = connectionFactory.createTopicConnection(); connection.start(); connection.close(); }
Example #22
Source File: ManagedQueueTopicConnection.java From ats-framework with Apache License 2.0 | 5 votes |
@Override public ConnectionConsumer createConnectionConsumer( Topic topic, String messageSelector, ServerSessionPool sessionPool, int maxMessages ) throws JMSException { return addConnectionConsumer( ((TopicConnection) connection).createConnectionConsumer(topic, messageSelector, sessionPool, maxMessages)); }
Example #23
Source File: TopicWildcardTest.java From ballerina-message-broker with Apache License 2.0 | 5 votes |
private void assertNullWithPublishSubscribeForTopics(String publishTopicName, String subscribeTopicName) throws Exception { int numberOfMessages = 100; InitialContext initialContext = ClientHelper .getInitialContextBuilder("admin", "admin", "localhost", port) .withTopic(publishTopicName) .withTopic(subscribeTopicName) .build(); TopicConnectionFactory connectionFactory = (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY); TopicConnection connection = connectionFactory.createTopicConnection(); connection.start(); TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic subscriberDestination = (Topic) initialContext.lookup(subscribeTopicName); TopicSubscriber subscriber = subscriberSession.createSubscriber(subscriberDestination); TopicSession publisherSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic publisherDestination = (Topic) initialContext.lookup(publishTopicName); TopicPublisher publisher = publisherSession.createPublisher(publisherDestination); for (int i = 0; i < numberOfMessages; i++) { publisher.publish(publisherSession.createTextMessage("Test message " + i)); } publisherSession.close(); Message message = subscriber.receive(1000); Assert.assertNull(message, "A message was received where no message was expected"); subscriberSession.close(); connection.close(); }
Example #24
Source File: JmsTopicSubscriberClosedTest.java From qpid-jms with Apache License 2.0 | 5 votes |
protected void createTestResources() throws Exception { connection = createTopicConnectionToMockProvider(); TopicSession session = ((TopicConnection) connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic destination = session.createTopic(_testName.getMethodName()); subscriber = session.createSubscriber(destination); subscriber.close(); }
Example #25
Source File: TransactionAwareConnectionFactoryProxy.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public TopicConnection createTopicConnection() throws JMSException { if (!(this.targetConnectionFactory instanceof TopicConnectionFactory)) { throw new javax.jms.IllegalStateException("'targetConnectionFactory' is no TopicConnectionFactory"); } TopicConnection targetConnection = ((TopicConnectionFactory) this.targetConnectionFactory).createTopicConnection(); return (TopicConnection) getTransactionAwareConnectionProxy(targetConnection); }
Example #26
Source File: DelegatingConnectionFactory.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public TopicConnection createTopicConnection(String username, String password) throws JMSException { ConnectionFactory cf = getTargetConnectionFactory(); if (cf instanceof TopicConnectionFactory) { return ((TopicConnectionFactory) cf).createTopicConnection(username, password); } else { Connection con = cf.createConnection(username, password); if (!(con instanceof TopicConnection)) { throw new javax.jms.IllegalStateException("'targetConnectionFactory' is not a TopicConnectionFactory"); } return (TopicConnection) con; } }
Example #27
Source File: PooledTopicPublisherTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 60000) public void testJmsPoolConnectionFactory() throws Exception { ActiveMQTopic topic = new ActiveMQTopic("test"); pcf = createPooledConnectionFactory(); connection = (TopicConnection) pcf.createConnection(); TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TopicPublisher publisher = session.createPublisher(topic); publisher.publish(session.createMessage()); }
Example #28
Source File: JmsPoolConnectionFactoryTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 60000) public void testTopicCreateConnectionWithCredentials() throws Exception { TopicConnection connection = cf.createTopicConnection("user", "pass"); assertNotNull(connection); assertEquals(1, cf.getNumConnections()); connection.close(); assertEquals(1, cf.getNumConnections()); }
Example #29
Source File: JmsPoolConnectionFactoryTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 60000) public void testTopicCreateConnection() throws Exception { TopicConnection connection = cf.createTopicConnection(); assertNotNull(connection); assertEquals(1, cf.getNumConnections()); connection.close(); assertEquals(1, cf.getNumConnections()); }
Example #30
Source File: JMSConnectionFactory.java From micro-integrator with Apache License 2.0 | 5 votes |
public TopicConnection createTopicConnection(String userName, String password) throws JMSException { try { return ((TopicConnectionFactory) (this.connectionFactory)).createTopicConnection(userName, password); } catch (JMSException e) { logger.error( "JMS Exception while creating topic connection through factory '" + this.connectionFactoryString + "' " + e.getMessage(), e); } return null; }