Package javax.jms

Examples of javax.jms.TopicPublisher


            /* Create the receivers */
            TopicSubscriber ts1 = s_rec1.createSubscriber(t, "size >= 5 OR (size < 5 AND color ='green')", false);
            TopicSubscriber ts2 = s_rec1.createSubscriber(t);
            TopicSubscriber ts3 = s_rec2.createSubscriber(t);
            /* Create a sender for sending messages */
            TopicPublisher tpub = s_send.createPublisher(t);
            /* create a message for sending */
            Message msg = s_send.createObjectMessage(new Integer(1));
            msg.setIntProperty("size", 2);
            msg.setStringProperty("color", "black");
            //Publish the message
            tpub.publish(msg);
            s_send.commit();

            Message msg1 = ts1.receiveNoWait();
            Message msg2 = ts2.receiveNoWait();
            Message msg3 = ts3.receiveNoWait();

            s_rec1.commit();
            s_rec2.commit();

            //message-properties do not match the selector
            Assert.assertNull(msg1);
            //the other subsrcibers do not use selectors
            Assert.assertNotNull(msg2);
            Assert.assertEquals("msg2 - object", 1, ((Integer)((ObjectMessage)msg2).getObject()).intValue());
            Assert.assertNotNull(msg3);
            Assert.assertEquals("msg3 - object", 1, ((Integer)((ObjectMessage)msg3).getObject()).intValue());

            /* create another message for sending */
            msg = s_send.createObjectMessage(new Integer(88));
            msg.setIntProperty("size", 2);
            msg.setStringProperty("color", "green");
            //Publish the message
            tpub.publish(msg);
            s_send.commit();

            msg1 = ts1.receiveNoWait();
            msg2 = ts2.receiveNoWait();
            msg3 = ts3.receiveNoWait();
View Full Code Here


            /* Create the receivers */
            TopicSubscriber ts1 = s_rec1.createSubscriber(t);
            TopicSubscriber ts2 = s_rec1.createSubscriber(t);
            TopicSubscriber ts3 = s_rec2.createSubscriber(t);
            /* Create a sender for sending messages */
            TopicPublisher tpub = s_send.createPublisher(t);
            tpub.setDisableMessageTimestamp(false);
            /* create a message for sending */
            Message msg = s_send.createObjectMessage(new Integer(123));
            msg.setJMSType(type);
           
            /* Send the message */
            tpub.publish(msg);
            Assert.assertNotNull("sender-JMSMessageID", msg.getJMSMessageID());
            /* Commit the sending session */
            s_send.commit();
            /* Receive the message */
            Message msg1 = ts1.receiveNoWait();
View Full Code Here

                Assert.fail("temporary topic must not be exposed to jndi");
            } catch(javax.naming.NamingException ex) {
                //as expected
            }

            TopicPublisher pub = ts.createPublisher(topic);
            ObjectMessage om = ts.createObjectMessage(new Integer(99));
            pub.publish(om);
            pub.close();

            pub = ts.createPublisher(tt);
            om = ts.createObjectMessage(new Integer(99));
            pub.publish(om);
            pub.close();

        } finally {
            try { ts.close()} catch(Exception ex) {}
            try { tc.close(); } catch(Exception ex) {}
        }
View Full Code Here

        try {
            tc = tcf.createTopicConnection("system", "system");
            ts = tc.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

            int num = 1000;
            TopicPublisher tp = ts.createPublisher(topic);
            ObjectMessage om = ts.createObjectMessage(new Integer(num++));
            tp.publish(om);
            om = ts.createObjectMessage(new Integer(num++));
            tp.publish(om);

            TopicSubscriber tsub = ts.createDurableSubscriber(topic, name);
            Message msg = tsub.receiveNoWait();

            Assert.assertNull("initial message", msg);

            om = ts.createObjectMessage(new Integer(num++));
            tp.publish(om);
            om = ts.createObjectMessage(new Integer(num++));
            tp.publish(om);

            msg = tsub.receiveNoWait();
            Assert.assertNotNull("fist message", msg);
            Assert.assertEquals("fist message", new Integer(1002),
                                            ((ObjectMessage)msg).getObject());
            msg = tsub.receiveNoWait();
            Assert.assertNotNull("second message", msg);
            Assert.assertEquals("second message", new Integer(1003),
                                            ((ObjectMessage)msg).getObject());

            tsub.close();

            om = ts.createObjectMessage(new Integer(num++));
            tp.publish(om);
            om = ts.createObjectMessage(new Integer(num++));
            tp.publish(om);

            tsub = ts.createDurableSubscriber(topic, name);

            msg = tsub.receiveNoWait();
            Assert.assertNotNull("third message", msg);
            Assert.assertEquals("third message", new Integer(1004),
                                            ((ObjectMessage)msg).getObject());
            msg = tsub.receiveNoWait();
            Assert.assertNotNull("fourth message", msg);
            Assert.assertEquals("fourth message", new Integer(1005),
                                            ((ObjectMessage)msg).getObject());

            ts.unsubscribe(name);

            om = ts.createObjectMessage(new Integer(num++));
            tp.publish(om);
            om = ts.createObjectMessage(new Integer(num++));
            tp.publish(om);

            tsub = ts.createDurableSubscriber(topic, name);

            msg = tsub.receiveNoWait();
            Assert.assertNull("after unsubscription", msg);

            om = ts.createObjectMessage(new Integer(num++));
            tp.publish(om);

            msg = tsub.receiveNoWait();
            Assert.assertNotNull("fith message", msg);
            Assert.assertEquals("fith message", new Integer(1008),
                                            ((ObjectMessage)msg).getObject());

            ts.unsubscribe(name);

            tsub.close();
            tp.close();

        } finally {
            try { ts.close()} catch(Exception ex) {}
            try { tc.close(); } catch(Exception ex) {}
        }
View Full Code Here

            if (base.isDestinationStyleQueue()) {
                QueueSender sender = (QueueSender)pooledSession.producer();
                sender.setTimeToLive(ttl);
                sender.send((Queue)base.targetDestination, jmsMessage, deliveryMode, priority, ttl);
            } else {
                TopicPublisher publisher = (TopicPublisher)pooledSession.producer();
                publisher.setTimeToLive(ttl);
                publisher.publish((Topic)base.targetDestination, jmsMessage, deliveryMode, priority, ttl);
            }
        }
View Full Code Here

        QueueConnection qc = null;
        QueueSession qs = null;
        try {
            tc = topicConnectionFactory().createTopicConnection();
            ts = tc.createTopicSession (true, 0);
            TopicPublisher sndr = ts.createPublisher (channelOutTopic());
            sndr.setDisableMessageID (true);
            ObjectMessage msg
                = ts.createObjectMessage ((Serializable)data);
            String processKey = ((Long)ctx.getPrimaryKey()).toString();
            msg.setStringProperty ("processKey", processKey);
            msg.setStringProperty ("channelName", channel);
            msg.setStringProperty ("messageType", "DATA");
            sndr.publish(msg);
            sndr.close();

            // Now clean up in queue
            qc = queueConnectionFactory().createQueueConnection();
            qs = qc.createQueueSession (true, 0);
            QueueReceiver rec = qs.createReceiver
View Full Code Here

        QueueConnection qc = null;
        QueueSession qs = null;
        try {
            tc = topicConnectionFactory().createTopicConnection();
            ts = tc.createTopicSession (true, 0);
            TopicPublisher sndr = ts.createPublisher (channelOutTopic());
            sndr.setDisableMessageID (true);
            Message msg = ts.createMessage();
            String processKey = ((Long)ctx.getPrimaryKey()).toString();
            msg.setStringProperty ("processKey", processKey);
            msg.setStringProperty ("messageType", "CLOSE_NOTIFICATION");
            sndr.publish(msg);
            sndr.close();

            // Now clean up in queue
            qc = queueConnectionFactory().createQueueConnection();
            qs = qc.createQueueSession (true, 0);
            QueueReceiver rec = qs.createReceiver
View Full Code Here

              }
              System.out.println("Topic - " + topicName + " ready");


              // Creating publisher
              TopicPublisher publisher = session.createPublisher(topic);
              System.out.println("Publisher ready");


              System.out.println("Publishing Messages ...");


              // Messages preparing

              // Messages Type
              TextMessage tMessage=null;     // Using simple text messages
              ObjectMessage oMessage=null;   // Using Lumos Alarm

              if (textMessages)
              {
                  // Setting the JMS Message
                  tMessage = session.createTextMessage();
                  tMessage.setText("JMS Text Message");
          System.out.println("Size of Text : " + size("JMS Text Message"));
          System.out.println("Size of JMS Text Message : " + size((Serializable)tMessage));         
              }
              else
              {
                  // Defining Message structure variables
                  AlarmImpl mAlarm;
          String mEntity = "Company" + "Lumos" + "Dept." + "R+D" + "User" + "Fabien" + "IP" + "10.0.0.137";
           String addData = "Vive la France ";
                  if (heavyweight)
                  {
                      addData = new String(new byte[weight]);
                      System.out.println("Heavyweight object building, size of addData : " + addData.length());

                  }
                  ArrayList mList = new ArrayList();
                  mList.add(0,"Item1");

                  // Creating an Alarm
                  mAlarm = new AlarmImpl(   // int id,
                                            0,
                                             // String name,
                                            "JMSTest",
                                            // EntityId src,
                                            mEntity,
                                            // String ct, - Condition Type
                                            "Message",
                                            // AlarmType type,
                                            "UNKNOWN",
                                            // AlarmSeverity sev,
                                            "WARNING",
                                            // long creTime,
                                            System.currentTimeMillis(),
                                            // boolean isSA, - Service Affecting ?
                                            true,
                                            // boolean isCAuto, - Auto Cleared
                                            false,
                                            // String add, - Additional Data
                                            addData,
                                            // List ad,
                                            mList,
                                            // boolean ack,
                                            true,
                                            // boolean isC - isCleared
                                            false
                                            );

                  // Setting the JMS Message
                  oMessage = session.createObjectMessage();
                  oMessage.setObject(mAlarm);
          System.out.println("Size of Alarm : " + size(mAlarm));
          System.out.println("Size of JMS Object Message : " + size((Serializable)oMessage));                           

              }

              // Sending Messages
              long startTime = System.currentTimeMillis();
              if (textMessages)
              {
                  do
                  {
                      for (int i=0;i<count;i++)
                      {
                          absCount++;
                          publisher.publish(tMessage, persistency, 1, Long.MAX_VALUE);
                          //System.out.print("\rmsg: " + absCount);
                          //Thread.sleep(sleepTime);
                      }
                      System.out.print("\rmsg: " + absCount);
                     
                      if (infiniteCount)
                      {
                          // Mesurements
                          long endTime = System.currentTimeMillis();
                          Date startDate = new Date(startTime);
                          Date endDate = new Date(endTime);
                          long duration_ms = endTime - startTime;
                          double duration_s = duration_ms/1000;
                          double msgRate = absCount/duration_s;
                          System.out.println();
                          System.out.println("Started sending at : " + startDate
                                              + "\nCount at : " + endDate
                                              + "\nDuration : " + duration_s + " sec."
                                              + "\nMessage count : " + absCount
                                              + "\nMessage sending rate : " + msgRate + " msg/s.\n");
                      }
                  }
                  while (infiniteCount);
              }
              else
              {
                  do
                  {
                      for (int i=0;i<count;i++)
                      {
                          absCount++;
                          publisher.publish(oMessage, persistency, 1, Long.MAX_VALUE);
                          //System.out.print("\rmsg: " + absCount);
                          //Thread.sleep(sleepTime);
                      }
                      System.out.print("\rmsg: " + absCount);
                     
                      if (infiniteCount)
                      {
                          // Mesurements
                          long endTime = System.currentTimeMillis();
                          Date startDate = new Date(startTime);
                          Date endDate = new Date(endTime);
                          long duration_ms = endTime - startTime;
                          double duration_s = duration_ms/1000;
                          double msgRate = absCount/duration_s;
                          System.out.println();
                          System.out.println("Started sending at : " + startDate
                                              + "\nCount at : " + endDate
                                              + "\nDuration : " + duration_s + " sec."
                                              + "\nMessage count : " + absCount
                                              + "\nMessage sending rate : " + msgRate + " msg/s.\n");
                      }
                  }
                  while (infiniteCount);
              }
              long endTime = System.currentTimeMillis();

              // Mesurements
              Date startDate = new Date(startTime);
              Date endDate = new Date(endTime);
              long duration_ms = endTime - startTime;
              double duration_s = duration_ms/1000;
              double msgRate = count/duration_s;
              System.out.println();
              System.out.println("Started sending at : " + startDate
                                  + "\nEnded sending at : " + endDate
                                  + "\nSent Duration : " + duration_s + " sec."
                                  + "\nMessage count : " + count
                                  + "\nMessage sending rate : " + msgRate + " msg/s.");


              // Closing communication objects
              publisher.close();
              session.close();
              connection.close();

        }
        catch (Exception exception)
View Full Code Here

   public void testTopic() throws Exception
   {
      printHeader();
      TopicSession session = getTopicSession();
      Topic topic = (Topic) getInitialContext().lookup(dest);
      TopicPublisher pub = session.createPublisher(topic);

      getLog().debug("TestTopic: " + dest + ": Sending 10st messages 1-10");

      for (int i = 1; i < 11; i++)
      {
         TextMessage message = session.createTextMessage();
         message.setText("Topic Message " + dest + " nr " + i);
         pub.publish(topic, message);
      }

      pub.close();
   }
View Full Code Here

                    System.err.println("Failed to get administered object"
                        + " exiting.....");
                    System.exit(-1);
                }

                TopicPublisher publisher = session.createPublisher(topic);

                // check the number of iterations that have been specified
                // on the command line. If it has not yet been specified
                // then default to 10.
                int count = 10;
                if (cmdline.exists("count")) {
                    try {
                        count = Integer.parseInt(cmdline.value("count"));
                    } catch (Exception exception) {
                        System.err.println("Illegal count value");
                        System.exit(-1);
                    }
                }

                // check if a sleep has been specified
                int sleep = 0;
                if (cmdline.exists("sleep")) {
                    try {
                        sleep = Integer.parseInt(cmdline.value("sleep"));
                    } catch (Exception exception) {
                        System.err.println("Illegal sleep value");
                        System.exit(-1);
                    }
                }

                // determine if the delivery mode should be persistent or
                // non persistent
                int delivery_mode = DeliveryMode.NON_PERSISTENT;
                if (cmdline.exists("persistent")) {
                    delivery_mode = DeliveryMode.PERSISTENT;
                }

                // create a text message
                Random rand = new Random((new Date()).getTime());
                for (int index = 0; index < count; index++) {
                    TextMessage message = session.createTextMessage(
                        "message " + index);
                    int priority = Math.abs(rand.nextInt() % 10);
                    publisher.publish(topic, message, delivery_mode,
                        priority, 0);

                    if (sleep > 0) {
                        try {
                            Thread.sleep(sleep);
                        } catch (Exception exception) {
                        }
                    }
                }

                System.out.println("The publisher published " + count +
                                   " messages on topic " + topic_name);

                if (mode.equals("ipc") || mode.equals("tcp") || mode.equals("http")) {
                    Thread.sleep(1000);
                }

                publisher.close();
                session.close();
                connection.close();                
            } else {
                System.err.println("Cannot publish messages under null " +
                    "topic");
View Full Code Here

TOP

Related Classes of javax.jms.TopicPublisher

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.