Package javax.jms

Examples of javax.jms.Session


    Queue queue = (Queue) ictx.lookup("MonitoringQueue");
    ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf");
    ictx.close();

    Connection cnx = cf.createConnection();
    Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer prod = sess.createProducer(queue);
    MessageConsumer cons = sess.createConsumer(queue);
    cnx.start();

    Message msg1 = sess.createMessage();
    msg1.setStringProperty("Joram#0:type=Destination,name=*",
                           "NbMsgsReceiveSinceCreation,NbMsgsSentToDMQSinceCreation");
    prod.send(msg1);
    System.out.println(" --> Monitoring message sent: " + msg1.getJMSMessageID());
   
View Full Code Here


    /**
     * Factory method to create the consumer
     */
    protected MessageConsumer createConsumer() throws JMSException {
        Session session = producer.getSession();
        if (subscriberName != null) {
            if (destination instanceof Topic) {
                Topic topic = (Topic) destination;
                return session.createDurableSubscriber(topic, subscriberName, messageSelector, noLocal);
            }
            else {
                throw new IllegalArgumentException("Cannot specify the subscriberName property when using a Queue destination");
            }

        }
        else {
            return session.createConsumer(destination, messageSelector, noLocal);
        }
    }
View Full Code Here

        return new SimpleMetadataStrategy(false);
    }


    protected void subscribeToQueue(JmsServiceExporter exporter, String queueName) throws JMSException {
        Session serverSession = createSession();
        Queue queue = serverSession.createQueue(queueName);
        MessageConsumer consumer = serverSession.createConsumer(queue);
        consumer.setMessageListener(exporter);
    }
View Full Code Here

  
   private void async(int ackMode, String type) {
      // Session.AUTO_ACKNOWLEDGE
      try {
         boolean transacted = false;
         Session consumerSession = connection.createSession(transacted, ackMode);
         MessageConsumer subscriber = consumerSession.createConsumer(this.topic);
         subscriber.setMessageListener(this);
         Session producerSession = connection.createSession(transacted, ackMode);
         MessageProducer publisher = producerSession.createProducer(this.topic);
         connection.start();

         for (int i=0; i < this.nmax; i++) {
            TextMessage msg = producerSession.createTextMessage();
            msg.setText("this is a " + type + " jms message nr. " + i);
            publisher.send(this.topic, msg);
         }
        
         if (ackMode == Session.CLIENT_ACKNOWLEDGE) {
View Full Code Here

   public void dummy() {
      // Session.AUTO_ACKNOWLEDGE
      try {
         boolean transacted = false;
        
         Session session = connection.createSession(transacted, Session.CLIENT_ACKNOWLEDGE);
         // String topic = "jms-topic";
         String topic = null;
         String sessionName = "hello/1";
         MessageProducer producer = session.createProducer(new XBDestination(topic, sessionName));
         // producer.setPriority(PriorityEnum.HIGH_PRIORITY.getInt());
         // producer.setDeliveryMode(DeliveryMode.PERSISTENT);
         TextMessage msg = session.createTextMessage();
         msg.setText("Hallo");
         producer.send(msg);
      }
      catch (Exception ex) {
         ex.printStackTrace();
View Full Code Here

      // async(Session.DUPS_OK_ACKNOWLEDGE, "dupsOkAcknowledge");
   }
  
   public void testSyncReceiver() {
      try {
         Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageConsumer consumer = consumerSession.createConsumer(this.topic);
         Session publisherSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageProducer publisher = publisherSession.createProducer(this.topic);
         int nmax = 3;

         // test receiveNoWait()
         TextMessage[] msgIn = new TextMessage[nmax];
         Message msg2 = null;
         for (int i=0; i < nmax; i++) {
            msgIn[i] = publisherSession.createTextMessage();
            msgIn[i].setText("msg " + i);
            publisher.send(this.topic, msgIn[i]);
         }
         for (int i=0; i < nmax; i++) {
            msg2 = consumer.receiveNoWait();
            if (!(msg2 instanceof TextMessage)) {
               assertTrue("received message if of wrong type, should be TextMessage but is '" + msg2.getClass().getName() + "'", false);
            }
            assertEquals("receive(): messages are not the same", msgIn[i].getText(), ((TextMessage)msg2).getText());        
         }
         msg2 = consumer.receiveNoWait();
         if (msg2 != null) {
            assertTrue("no message was sent, so null should have been returned here but it was " + msg.toString(), false);
         }
        
         // test receive(long)
         msgIn = new TextMessage[nmax];
         for (int i=0; i < nmax; i++) {
            msgIn[i] = publisherSession.createTextMessage();
            msgIn[i].setText("msg " + i);
            publisher.send(this.topic, msgIn[i]);
         }
         for (int i=0; i < nmax; i++) {
            msg2 = consumer.receive(200L);
            if (!(msg2 instanceof TextMessage)) {
               assertTrue("received message if of wrong type, should be TextMessage but is '" + msg2.getClass().getName() + "'", false);
            }
            assertEquals("receive(): messages are not the same", msgIn[i].getText(), ((TextMessage)msg2).getText());        
         }
         msg2 = consumer.receive(200L);
         if (msg2 != null) {
            assertTrue("no message was sent, so null should have been returned here but it was " + msg.toString(), false);
         }

         // test receive()
         msgIn = new TextMessage[nmax];
         for (int i=0; i < nmax; i++) {
            msgIn[i] = publisherSession.createTextMessage();
            msgIn[i].setText("msg " + i);
            publisher.send(this.topic, msgIn[i]);
         }
         for (int i=0; i < nmax; i++) {
            msg2 = consumer.receive();
View Full Code Here

    }

    public void testTimeout() throws Exception {
        SingleThreadedRequestor requestor = (SingleThreadedRequestor) createRequestor(getDestinationName());

        Session session = createSession();
        MessageConsumer receiver = session.createConsumer(session.createQueue(getDestinationName()));

        // clear old messages
        while (receiver.receive(1) != null) {
            ;
        }

        requestor.oneWay(null, session.createTextMessage("bonson"), 1);
        Thread.sleep(50);
        assertNull(receiver.receive(1));

        requestor.oneWay(null, session.createTextMessage("bonson2"), -1);
        TextMessage message = (TextMessage) receiver.receive(1000);
        assertNotNull(message);
        assertEquals("bonson2", message.getText());
    }
View Full Code Here

    }

    public void testTimeouUsingPermanentQueue() throws Exception {
        SingleThreadedRequestor requestor = (SingleThreadedRequestor) createRequestor(getDestinationName(), getDestinationName() + ".ClientInbound");

        Session session = createSession();
        MessageConsumer receiver = session.createConsumer(session.createQueue(getDestinationName()));

        // clear old messages
        while (receiver.receive(1) != null) {
            ;
        }

        requestor.oneWay(null, session.createTextMessage("bonson"), 1);
        Thread.sleep(50);
        assertNull(receiver.receive(1));

        requestor.oneWay(null, session.createTextMessage("bonson2"), -1);
        TextMessage message = (TextMessage) receiver.receive(1000);
        assertNotNull(message);
        assertEquals("bonson2", message.getText());
    }
View Full Code Here

        assertEquals("size of results: " + results, 2, results.size());
    }

    protected Requestor createRequestor(String name) throws Exception {
        Session session = createSession();
        JmsProducer producer = createJmsProducer();
        return new MultiplexingRequestor(session, producer, session.createQueue(name));
    }
View Full Code Here

        }
        return connection;
    }

    protected Requestor createRequestor(String serverDestinationName) throws Exception {
        Session session = createSession();
        JmsProducer producer = createJmsProducer();
        return new SingleThreadedRequestor(session, producer, session.createQueue(serverDestinationName));
    }
View Full Code Here

TOP

Related Classes of javax.jms.Session

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.