@Override public Message createMessage(Session session) throws JMSException { ObjectMessage om = session.createObjectMessage(objectMessage); om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay); om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1 * 1000); om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1); return om; } });
/** * emits an JMS message to a queue, <b>inside a JTA transaction</b> * * @param payload the message body * @param ctx to send the message inside the ctx transaction * @param queueName * @throws Exception */ public static void emitJMSMessage(final Serializable payload, final EJBContext ignored, final String queueName, final long delayMillis, final long deliveriesCounter) throws Exception { InitialContext ctx = new InitialContext(); ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/QueueConnectionFactory"); Queue queue = (Queue) ctx.lookup(queueName); Connection conn = cf.createConnection(); Session sess = conn.createSession(true, Session.AUTO_ACKNOWLEDGE); MessageProducer mp = sess.createProducer(queue); ObjectMessage msg = sess.createObjectMessage(); if (delayMillis > 0) { msg.setLongProperty("scheduleDate", System.currentTimeMillis() + delayMillis); } msg.setLongProperty("deliveriesCounter", deliveriesCounter); msg.setObject(payload); mp.send(msg); sess.close(); conn.close(); }
objectMessage.setStringProperty(property.getKey(), (String) value); } else if (value instanceof Long) { objectMessage.setLongProperty(property.getKey(), (Long) value);
objectMessage.setStringProperty(property.getKey(), (String) value); } else if (value instanceof Long) { objectMessage.setLongProperty(property.getKey(), (Long) value);
Queue q = (Queue) ServiceLocator.getInstance().getDestination("QUEUE"); QueueConnectionFactory factory = (QueueConnectionFactory) ServiceLocator.getInstance().getConnectionFactory( "java:/ConnectionFactory"); QueueConnection connection = factory.createQueueConnection(); QueueSession session = null; QueueSender sender = null; session = connection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); sender = session.createSender(q); ObjectMessage msg = session.createObjectMessage(); if (redelivedCount > 0) { msg.setIntProperty("redelivedCount", redelivedCount); // schedule to run in 10 secs msg.setLongProperty("_AMQ_SCHED_DELIVERY", System.currentTimeMillis() + 10000); } msg.setStringProperty("action", action); msg.setObject(params); sender.send(msg);