Package javax.jms

Examples of javax.jms.TopicSession


        final InitialContext ctx = new InitialContext();
        final TopicConnectionFactory factory = (TopicConnectionFactory) ctx.lookup("java:/JmsXA");
        final TopicConnection connection = factory.createTopicConnection();
        connection.start();
        try {
            final TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            final Message message = session.createTextMessage("Test");
            final Destination destination = (Destination) ctx.lookup("topic/test");
            final MessageProducer producer = session.createProducer(destination);
            producer.send(message);
            producer.close();
        } finally {
            //connection.stop();
        }
View Full Code Here


    try {
      final TopicConnection connection = topicFactory.createTopicConnection();

      connection.start();

      final TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

      final TopicPublisher publisher = session.createPublisher(topic);

      final MapMessage message = session.createMapMessage();

      message.setString("nome", "Regis");
      message.setInt("idade", 23);

      publisher.send(message);

      // close resources
      publisher.close();
      session.close();
      connection.close();
    } catch (JMSException e) {
      log.error("", e);
    } catch (Exception e) {
      log.error("", e);
View Full Code Here

        protected ListenerSession createListenerSession(javax.jms.Connection connection,
                                                        Subscription subscription)
            throws JMSException
        {
            TopicSession session = createTopicSession((TopicConnection)connection,
                                                      subscription.m_ackMode);
            TopicSubscriber subscriber = createSubscriber(session,
                                                (TopicSubscription)subscription);
            return new TopicListenerSession(session, subscriber,
                                                (TopicSubscription)subscription);
View Full Code Here

        }

        protected SendSession createSendSession(javax.jms.Connection connection)
            throws JMSException
        {
            TopicSession session = createTopicSession((TopicConnection)connection,
                                            JMSConstants.DEFAULT_ACKNOWLEDGE_MODE);
            TopicPublisher publisher = session.createPublisher(null);
            return new TopicSendSession(session, publisher);
        }
View Full Code Here

        outboundMessageConvertor.setConnection(outboundTopicConnection);
    }

    protected void initializeInboundTopicBridges() throws JMSException {
        if (inboundTopicBridges != null) {
            TopicSession outboundSession = outboundTopicConnection
                .createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            TopicSession localSession = localTopicConnection.createTopicSession(false,
                                                                                Session.AUTO_ACKNOWLEDGE);
            for (int i = 0; i < inboundTopicBridges.length; i++) {
                InboundTopicBridge bridge = inboundTopicBridges[i];
                String localTopicName = bridge.getLocalTopicName();
                Topic activemqTopic = createActiveMQTopic(localSession, localTopicName);
                String topicName = bridge.getInboundTopicName();
                Topic foreignTopic = createForeignTopic(outboundSession, topicName);
                bridge.setConsumerTopic(foreignTopic);
                bridge.setProducerTopic(activemqTopic);
                bridge.setProducerConnection(localTopicConnection);
                bridge.setConsumerConnection(outboundTopicConnection);
                if (bridge.getJmsMessageConvertor() == null) {
                    bridge.setJmsMessageConvertor(getInboundMessageConvertor());
                }
                bridge.setJmsConnector(this);
                addInboundBridge(bridge);
            }
            outboundSession.close();
            localSession.close();
        }
    }
View Full Code Here

        }
    }

    protected void initializeOutboundTopicBridges() throws JMSException {
        if (outboundTopicBridges != null) {
            TopicSession outboundSession = outboundTopicConnection
                .createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            TopicSession localSession = localTopicConnection.createTopicSession(false,
                                                                                Session.AUTO_ACKNOWLEDGE);
            for (int i = 0; i < outboundTopicBridges.length; i++) {
                OutboundTopicBridge bridge = outboundTopicBridges[i];
                String localTopicName = bridge.getLocalTopicName();
                Topic activemqTopic = createActiveMQTopic(localSession, localTopicName);
                String topicName = bridge.getOutboundTopicName();
                Topic foreignTopic = createForeignTopic(outboundSession, topicName);
                bridge.setConsumerTopic(activemqTopic);
                bridge.setProducerTopic(foreignTopic);
                bridge.setProducerConnection(outboundTopicConnection);
                bridge.setConsumerConnection(localTopicConnection);
                if (bridge.getJmsMessageConvertor() == null) {
                    bridge.setJmsMessageConvertor(getOutboundMessageConvertor());
                }
                bridge.setJmsConnector(this);
                addOutboundBridge(bridge);
            }
            outboundSession.close();
            localSession.close();
        }
    }
View Full Code Here

                    protected Destination processReplyToDestination(Destination destination) {
                        return null;
                    }
                };
                try {
                    TopicSession replyToConsumerSession = ((TopicConnection)replyToConsumerConnection)
                        .createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
                    Topic replyToConsumerTopic = replyToConsumerSession.createTemporaryTopic();
                    replyToConsumerSession.close();
                    bridge.setConsumerTopic(replyToConsumerTopic);
                    bridge.setProducerTopic(replyToProducerTopic);
                    bridge.setProducerConnection((TopicConnection)replyToProducerConnection);
                    bridge.setConsumerConnection((TopicConnection)replyToConsumerConnection);
                    bridge.setDoHandleReplyTo(false);
                    if (bridge.getJmsMessageConvertor() == null) {
                        bridge.setJmsMessageConvertor(getInboundMessageConvertor());
                    }
                    bridge.setJmsConnector(this);
                    bridge.start();
                    LOG.info("Created replyTo bridge for " + replyToProducerTopic);
                } catch (Exception e) {
                    LOG.error("Failed to create replyTo bridge for topic: " + replyToProducerTopic, e);
                    return null;
                }
                replyToBridges.put(replyToProducerTopic, bridge);
            }
            return bridge.getConsumerTopic();
        } else {
            OutboundTopicBridge bridge = (OutboundTopicBridge)replyToBridges.get(replyToProducerTopic);
            if (bridge == null) {
                bridge = new OutboundTopicBridge() {
                    protected Destination processReplyToDestination(Destination destination) {
                        return null;
                    }
                };
                try {
                    TopicSession replyToConsumerSession = ((TopicConnection)replyToConsumerConnection)
                        .createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
                    Topic replyToConsumerTopic = replyToConsumerSession.createTemporaryTopic();
                    replyToConsumerSession.close();
                    bridge.setConsumerTopic(replyToConsumerTopic);
                    bridge.setProducerTopic(replyToProducerTopic);
                    bridge.setProducerConnection((TopicConnection)replyToProducerConnection);
                    bridge.setConsumerConnection((TopicConnection)replyToConsumerConnection);
                    bridge.setDoHandleReplyTo(false);
View Full Code Here

        return new AMQSession(config, this, type, useBytesMessage);
    }

    TopicSession createTopicSession()
    {
        TopicSession result = null;

        while (result == null) {
            try {
                result = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            }
View Full Code Here

   public void testCannotReceiveMessageOnStoppedConnection() throws Exception
   {
      TopicConnection conn1 = ((TopicConnectionFactory)cf).createTopicConnection();
      TopicConnection conn2 = ((TopicConnectionFactory)cf).createTopicConnection();
     
      TopicSession sess1 = conn1.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
      TopicSession sess2 = conn2.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
     
      TopicSubscriber sub1 = sess1.createSubscriber(topic1);
      TopicSubscriber sub2 = sess2.createSubscriber(topic1);
     
      conn1.start();
     
      Connection conn3 = cf.createConnection();
     
View Full Code Here

  
         TopicConnection conn = cf.createTopicConnection();
  
         conn.setClientID("Client1");
  
         TopicSession s = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageProducer prod = s.createProducer(topic);
         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
  
         // Create 1 durable subscription and 1 non-durable subscription
         s.createDurableSubscriber(topic, "Durable1");
         s.createSubscriber(topic);
        
         // Send 1 message
         prod.send(s.createTextMessage("First one"));        
        
         ObjectName destObjectName =
            new ObjectName("jboss.messaging.destination:service=Topic,name=TopicRemoveAllMessages");
        
         int count = ((Integer)ServerManagement.getAttribute(destObjectName, "AllMessageCount")).intValue();
        
         assertEquals(2, count);
        
         // Start the connection for delivery
         conn.start();
        
         // Remove all messages from the topic
        
         //Need to pause since delivery may still be in progress
         Thread.sleep(2000);
        
         count = ((Integer)ServerManagement.getAttribute(destObjectName, "AllMessageCount")).intValue();
        
         //Note we only keep track of deliveries for DURABLE subs so count should be 1
         //no durable are effectively acked immediately
        
         assertEquals(1, count);
        
         //This should fail since you cannot remove messages if there are deliveries in progress
         try
         {
           ServerManagement.invoke(destObjectName, "removeAllMessages", null, null);
           fail();
         }
         catch (Exception e)
         {
           //OK
         }
  
         count = ((Integer)ServerManagement.getAttribute(destObjectName, "AllMessageCount")).intValue();
        
         assertEquals(1, count);
                 
         // Now close the connection
         conn.close();
        
         ServerManagement.invoke(destObjectName, "removeAllMessages", null, null);
        
         count = ((Integer)ServerManagement.getAttribute(destObjectName, "AllMessageCount")).intValue();
        
         assertEquals(0, count);
        
         // Connect again to the same topic
         conn = cf.createTopicConnection();
         conn.setClientID("Client1");
         s = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
         prod = s.createProducer(topic);
         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
  
         // Send another message
         prod.send(s.createTextMessage("Second one"));
        
         count = ((Integer)ServerManagement.getAttribute(destObjectName, "AllMessageCount")).intValue();
        
         assertEquals(1, count);
View Full Code Here

TOP

Related Classes of javax.jms.TopicSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.