@Override public Session createSession(Connection con) throws JMSException { return ((TopicConnection) con).createTopicSession( synchedLocalTransactionAllowed, Session.AUTO_ACKNOWLEDGE); } @Override
/** * 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); } }
@Override protected synchronized MessageProducer createProducer() throws JMSException { if (producerConnection == null) return null; producerSession = producerConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); producer = producerSession.createPublisher(null); return producer; }
@Override public TopicSession createTopicSession(boolean transacted, int acknowledgeMode) throws JMSException { checkTopicConnection(); TopicSession ts = ((TopicConnection) delegate).createTopicSession(transacted, acknowledgeMode); return TracingSession.create(ts, jmsTracing); }
public JMSSink( String tcfBindingName, String topicBindingName, String username, String password) { try { Context ctx = new InitialContext(); TopicConnectionFactory topicConnectionFactory; topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName); TopicConnection topicConnection = topicConnectionFactory.createTopicConnection(username, password); topicConnection.start(); TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = (Topic)ctx.lookup(topicBindingName); TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic); topicSubscriber.setMessageListener(this); } catch(JMSException e) { logger.error("Could not read JMS message.", e); } catch(NamingException e) { logger.error("Could not read JMS message.", e); } catch(RuntimeException e) { logger.error("Could not read JMS message.", e); } }
@Override protected MessageConsumer createConsumer() throws JMSException { // set up the consumer if (consumerConnection == null) return null; consumerSession = consumerConnection.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE); MessageConsumer consumer = null; if (consumerName != null && consumerName.length() > 0) { if (selector != null && selector.length() > 0) { consumer = consumerSession.createDurableSubscriber(consumerTopic, consumerName, selector, false); } else { consumer = consumerSession.createDurableSubscriber(consumerTopic, consumerName); } } else { if (selector != null && selector.length() > 0) { consumer = consumerSession.createSubscriber(consumerTopic, selector, false); } else { consumer = consumerSession.createSubscriber(consumerTopic); } } consumer.setMessageListener(this); return consumer; }
topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
protected void initializeInboundDestinationBridgesOutboundSide(TopicConnection connection) throws JMSException { if (inboundTopicBridges != null) { TopicSession outboundSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); for (InboundTopicBridge bridge : inboundTopicBridges) { String TopicName = bridge.getInboundTopicName(); Topic foreignTopic = createForeignTopic(outboundSession, TopicName); bridge.setConsumer(null); bridge.setConsumerTopic(foreignTopic); bridge.setConsumerConnection(connection); bridge.setJmsConnector(this); addInboundBridge(bridge); } outboundSession.close(); } }
protected void initializeOutboundDestinationBridgesLocalSide(TopicConnection connection) throws JMSException { if (outboundTopicBridges != null) { TopicSession localSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); for (OutboundTopicBridge bridge : outboundTopicBridges) { String localTopicName = bridge.getLocalTopicName(); Topic activemqTopic = createActiveMQTopic(localSession, localTopicName); bridge.setConsumer(null); bridge.setConsumerTopic(activemqTopic); bridge.setConsumerConnection(connection); bridge.setJmsConnector(this); addOutboundBridge(bridge); } localSession.close(); } }
given(con.createTopicSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession); given(txSession.getTransacted()).willReturn(true); given(con.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession); con1.start(); TopicConnection con2 = scf.createTopicConnection(); Session session2 = con2.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE); session2.close(); session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
protected void initializeOutboundDestinationBridgesOutboundSide(TopicConnection connection) throws JMSException { if (outboundTopicBridges != null) { TopicSession outboundSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); for (OutboundTopicBridge bridge : outboundTopicBridges) { String topicName = bridge.getOutboundTopicName(); Topic foreignTopic = createForeignTopic(outboundSession, topicName); bridge.setProducerTopic(foreignTopic); bridge.setProducerConnection(connection); if (bridge.getJmsMessageConvertor() == null) { bridge.setJmsMessageConvertor(getOutboundMessageConvertor()); } bridge.setJmsConnector(this); addOutboundBridge(bridge); } outboundSession.close(); } }
protected void initializeInboundDestinationBridgesLocalSide(TopicConnection connection) throws JMSException { if (inboundTopicBridges != null) { TopicSession localSession = connection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE); for (InboundTopicBridge bridge : inboundTopicBridges) { String localTopicName = bridge.getLocalTopicName(); Topic activemqTopic = createActiveMQTopic(localSession, localTopicName); bridge.setProducerTopic(activemqTopic); bridge.setProducerConnection(connection); if (bridge.getJmsMessageConvertor() == null) { bridge.setJmsMessageConvertor(getInboundMessageConvertor()); } bridge.setJmsConnector(this); addInboundBridge(bridge); } localSession.close(); } }
try { TopicSession replyToConsumerSession = ((TopicConnection)replyToConsumerConnection) .createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic replyToConsumerTopic = replyToConsumerSession.createTemporaryTopic(); replyToConsumerSession.close(); try { TopicSession replyToConsumerSession = ((TopicConnection)replyToConsumerConnection) .createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic replyToConsumerTopic = replyToConsumerSession.createTemporaryTopic(); replyToConsumerSession.close();
sess = conn.createTopicSession(useTransaction, ackMode);
public JMSTopicSink(String tcfBindingName, String topicBindingName, String username, String password) { try { Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); env.put(Context.PROVIDER_URL, "tcp://localhost:61616"); Context ctx = new InitialContext(env); TopicConnectionFactory topicConnectionFactory; topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName); System.out.println("Topic Cnx Factory found"); Topic topic = (Topic) ctx.lookup(topicBindingName); System.out.println("Topic found: " + topic.getTopicName()); TopicConnection topicConnection = topicConnectionFactory .createTopicConnection(username, password); System.out.println("Topic Connection created"); TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic); topicSubscriber.setMessageListener(this); topicConnection.start(); System.out.println("Topic Connection started"); } catch (Exception e) { logger.error("Could not read JMS message.", e); } }
public JMSSink( String tcfBindingName, String topicBindingName, String username, String password) { try { Context ctx = new InitialContext(); TopicConnectionFactory topicConnectionFactory; topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName); TopicConnection topicConnection = topicConnectionFactory.createTopicConnection(username, password); topicConnection.start(); TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = (Topic)ctx.lookup(topicBindingName); TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic); topicSubscriber.setMessageListener(this); } catch(JMSException e) { logger.error("Could not read JMS message.", e); } catch(NamingException e) { logger.error("Could not read JMS message.", e); } catch(RuntimeException e) { logger.error("Could not read JMS message.", e); } }
topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
this.topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
@Create public void create() throws JMSException, NamingException { //TODO: i really want a transactional session! topicSession = TopicConnection.instance().createTopicSession(false, Session.AUTO_ACKNOWLEDGE); }
@Test public void testCreateQueueOnATopicSession() throws Exception { TopicConnection c = (TopicConnection) getConnectionFactory().createConnection(); TopicSession s = c.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); try { s.createQueue("TestQueue"); ProxyAssertSupport.fail("should throw IllegalStateException"); } catch (javax.jms.IllegalStateException e) { // OK } c.close(); }