Examples of MessageConsumer


Examples of javax.jms.MessageConsumer

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

    Connection cnx = cf.createConnection();
    Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer subs = sess.createConsumer(topic);

    subs.setMessageListener(new MonitorMsgListener());

    cnx.start();

    System.in.read();
    cnx.close();
View Full Code Here

Examples of javax.jms.MessageConsumer

    ictx.close();

    Connection cnx = cf.createConnection("anonymous", "anonymous");

    Session session = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(dmq);

    cnx.start();
   
    for (int i=0; i<3; i++) {
      TextMessage msg = (TextMessage) consumer.receive();
      System.out.println("\nreceives: \"" + msg.getText() + "\", " +
                         "JMS_JORAM_ERRORCOUNT=" + msg.getIntProperty("JMS_JORAM_ERRORCOUNT"));
      System.out.println("JMS_JORAM_ERRORCAUSE_1=" + msg.getStringProperty("JMS_JORAM_ERRORCAUSE_1") + ", " +
                         "JMS_JORAM_ERRORCODE_1=" + msg.getStringProperty("JMS_JORAM_ERRORCODE_1"));
      System.out.println("JMSXDeliveryCount=" + msg.getIntProperty("JMSXDeliveryCount"));
View Full Code Here

Examples of javax.jms.MessageConsumer

    Connection cnx = cf.createConnection();
    Session prodSession = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session consSession = cnx.createSession(true, 0);
   
    MessageProducer producer = prodSession.createProducer(null);
    MessageConsumer consumer = consSession.createConsumer(queue1);

    cnx.start();

    // Producing messages with a very short time to live: 20 ms.
    System.out.println("Sends Message1 with a very short time to live");
    TextMessage msg = prodSession.createTextMessage("Message1");
    producer.send(queue1, msg, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 20);
   
    // Waiting for the message to be expired.
    System.out.println("Waits for the message to be expired");
    Thread.sleep(100);

    msg = (TextMessage) consumer.receiveNoWait();
    System.out.println("receives: " + msg);
   
    // Producing "undeliverable" messages
    System.out.println("Send Message2");  
    msg = prodSession.createTextMessage("Message2");
    producer.send(queue1, msg);
   
    msg = (TextMessage) consumer.receive();
    System.out.println("Receives: " + msg.getText() + " then deny it!");
    consSession.rollback();
   
    msg = (TextMessage) consumer.receive();
    System.out.println("Receives: " + msg.getText() + " then deny it!");
    consSession.rollback();
       
    // Producing "forbidden" messages
    System.out.println("Send Message3");  
View Full Code Here

Examples of javax.jms.MessageConsumer

    Topic topic = (Topic) jndiCtx.lookup("topic");
    jndiCtx.close();
   
    Connection cnx = tcf.createConnection("anonymous", "anonymous");
    Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer sub = sess.createConsumer(topic);

    sub.setMessageListener(new Listener());

    cnx.start();

    System.in.read();
View Full Code Here

Examples of javax.jms.MessageConsumer

    ictx.close();

    Connection cnx = cf.createConnection();
    Session qSess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);

    MessageConsumer qConsumer = qSess.createConsumer(queue);
    cnx.start();

    TextMessage msg;

    for (int i = 0; i < 10; i++) {
      msg = (TextMessage) qConsumer.receive();
      System.out.println("Message received from queue: " + msg.getText());
    }

    cnx.close();
  }
View Full Code Here

Examples of javax.jms.MessageConsumer

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

    Connection cnx = cf.createConnection();
    Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer recv = sess.createConsumer(queue);
    Message msg;

    cnx.start();

    msg = recv.receive();
     
    String u = msg.getStringProperty("url");
    System.out.println("url = " + u);
    System.out.println("crc=" + msg.getLongProperty("crc"));
    System.out.println("ack=" + msg.getBooleanProperty("ack"));
View Full Code Here

Examples of javax.jms.MessageConsumer

    AdminModule.disconnect();

    Connection cnx = cf.createConnection("anonymous", "anonymous");
    Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer sub = sess.createConsumer(topic);

    sub.setMessageListener(new Listener());

    cnx.start();

    System.in.read();
View Full Code Here

Examples of javax.jms.MessageConsumer

    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());
    try {
      Monitor.doReport(msg2);
    } catch (JMSException exc) {
View Full Code Here

Examples of javax.jms.MessageConsumer

    protected Responder(String selector) {
      this.selector = selector;
    }
   
    public void run() {
      MessageConsumer consumer = null;
      try {
        consumer = session.createConsumer(responseQueue, " " + TaskServiceConstants.SELECTOR_NAME + " like '" + selector + "%' ");
        ObjectMessage serverMessage = (ObjectMessage) consumer.receive();
        if (serverMessage != null) {
          ((JMSTaskClientHandler) handler).messageReceived(session, readMessage(serverMessage), responseQueue, selector);
        }
      } catch (JMSException e) {
        if (!"102".equals(e.getErrorCode())) {
          throw new RuntimeException("No se pudo recibir respuesta JMS", e);
        }
        logger.info(e.getMessage());
        return;
      } catch (Exception e) {
        throw new RuntimeException("Error inesperado recibiendo respuesta JMS", e);
      } finally {
        if (consumer != null) {
          try {
            consumer.close();
          } catch (Exception e) {
            logger.info("No se pudo cerrar el consumer: " + e.getMessage());
          }
        }
      }
View Full Code Here

Examples of javax.jms.MessageConsumer


    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
TOP
Copyright © 2018 www.massapi.com. 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.