<%@ page language="java" import="java.lang.*, javax.jms.*, org.jboss.mq.SpyQueue" %> <%@ page language="java" import="javax.naming.*" %> <% long timestamp; int NUMBER_OF_MESSAGES = 2; InitialContext ic = null; String provider = "jnp://192.168.4.151:1099"; String connectionFactoryName = "java:/JmsXA"; ConnectionFactory connectionFactory = null; Destination queue = null; javax.jms.Connection connection = null; javax.jms.Session mySession = null; MessageProducer producer = null; java.util.Properties p = new java.util.Properties(); p.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); p.put(javax.naming.Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); p.put(javax.naming.Context.PROVIDER_URL, provider); p.put("jnp.disableDiscovery", "true"); p.put("jnp.discoveryTimeout", "10000"); p.put("jnp.timeout", "10000"); p.put("jnp.sotimeout", "10000"); try{ ic = new InitialContext(); connectionFactory = (ConnectionFactory)ic.lookup(connectionFactoryName); connection = connectionFactory.createConnection(); mySession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); //looking up the queue from the remote instance requires to create // a context just for this purpose //InitialContext remoteIC = new InitialContext(p); //queue = (Destination)remoteIC.lookup("queue/testQueue"); // not portable way by creating a SpyQueue object queue = new SpyQueue("testQueue"); producer = mySession.createProducer(queue); connection.start(); for(int i = 0; i < NUMBER_OF_MESSAGES; i++) { //System.out.println("sending message #"+i); Message m = mySession.createObjectMessage(new Integer(i)); //m.setStringProperty("StringProperty", "luc"); m.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); /* JBossMQ specific property - JMS_JBOSS_SCHEDULED_DELIVERY long ONE_HOUR_MILLIS = 15 * 60 * 1000; long now = System.currentTimeMillis(); m.setLongProperty("JMS_JBOSS_SCHEDULED_DELIVERY", now + ONE_HOUR_MILLIS); */ /* JBossMQ specific property - JMS_JBOSS_REDELIVERY_LIMIT */ m.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 3); out.println("
Sending message " +m); producer.send(m); } //mySession.commit(); timestamp = System.currentTimeMillis(); out.println("
" +NUMBER_OF_MESSAGES + " messages sent successfully"); }catch(Exception e){ out.println("
e= "+e); }finally{ out.println("
finally"); if(connection != null) connection.close(); } %>