Package javax.jms

Examples of javax.jms.MessageProducer


    ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf");
    ictx.close();

    Connection cnx = cf.createConnection();
    Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = sess.createProducer(null);

    Message msg = sess.createMessage();
    msg.setStringProperty("expiration", "0");
    msg.setStringProperty("persistent", "true");
    msg.setStringProperty("acquisition.period", "30000");
    msg.setStringProperty("collector.url", "http://www.gnu.org/licenses/lgpl-3.0.txt");
    msg.setStringProperty("collector.type", "5");
    producer.send(queue, msg);
//    producer.send(topic, msg);

    System.out.println("messages sent.");

    cnx.close();
View Full Code Here


    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());
   
    Message msg2 = cons.receive();
   
    System.out.println(" --> Monitoring message received: " + msg2.getJMSMessageID());
View Full Code Here

    if (destination instanceof Queue) {
      name = ((Queue) destination).getQueueName();
    } else if (destination instanceof Topic) {
      name = ((Topic) destination).getTopicName();
    }
    MessageProducer producer = (MessageProducer) this.producers.get(name);
    if (producer == null) {
      producer = session.createProducer(destination);
      this.producers.put(name, producer);
    }
    this.handler.messageReceived(new JMSSessionWriter(session, producer, selector), message);
View Full Code Here

    if (destination instanceof Queue) {
      name = ((Queue) destination).getQueueName();
    } else if (destination instanceof Topic) {
      name = ((Topic) destination).getTopicName();
    }
    MessageProducer producer = (MessageProducer) this.producers.get(name);
    if (producer == null) {
      producer = session.createProducer(destination);
      this.producers.put(name, producer);
    }
    this.handler.messageReceived(new JMSSessionWriter(session, producer, selector), message);
View Full Code Here

         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) {
            for (int i=0; i < this.nmax; i++) {
               Thread.sleep(250L);
View Full Code Here

        
         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

   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();
            if (!(msg2 instanceof TextMessage)) {
               assertTrue("received message if of wrong type, should be TextMessage but is '" + msg2.getClass().getName() + "'", false);
View Full Code Here

        return producer;
    }

    public void close() throws JMSException {
        if (producer != null) {
            MessageProducer tmp = producer;
            producer = null;
            tmp.close();
        }
        if (session != null) {
            Session tmp = session;
            session = null;
            tmp.close();
        }
    }
View Full Code Here

    public void testPooledSession() throws Exception {
           
        Session sess =  EasyMock.createMock(Session.class);
        Destination dest = EasyMock.createMock(Destination.class);
        MessageProducer mproducer = EasyMock.createMock(MessageProducer.class);
        MessageConsumer mconsumer = EasyMock.createMock(MessageConsumer.class);
      
        PooledSession ps = new PooledSession(sess, dest, mproducer, mconsumer);
      
        assertTrue(ps.session().equals(sess));
View Full Code Here

      }

      // send a bunch of messages and let them accumulate in the queue
      Connection conn = cf.createConnection();
      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer prod = session.createProducer(queue);

      int messageCount = 20;

      for(int i = 0; i < messageCount; i++)
      {
         Message m = session.createTextMessage("krakatau" + i);
         prod.send(m);
      }

      conn.close();

      // make sure messages made it to the queue
View Full Code Here

TOP

Related Classes of javax.jms.MessageProducer

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.