List of usage examples for javax.jms DeliveryMode PERSISTENT
int PERSISTENT
To view the source code for javax.jms DeliveryMode PERSISTENT.
Click Source Link
From source file:com.centurylink.mdw.util.MDWMessageProducer.java
/** * @param message/* ww w .ja v a2 s .c o m*/ * @param correlationId * @throws JMSException */ public void sendMessage(String message, String correlationId) throws JMSException { sendMessage(message, null, correlationId, null, 0, DeliveryMode.PERSISTENT); }
From source file:RequesterTool.java
public void run() { Connection connection = null; try {//from ww w.j av a 2 s. co m System.out.println("Connecting to URL: " + url); System.out.println("Publishing a Message with size " + messageSize + " to " + (topic ? "topic" : "queue") + ": " + subject); System.out.println("Using " + (persistent ? "persistent" : "non-persistent") + " messages"); System.out.println("Sleeping between publish " + sleepTime + " ms"); // Create the connection ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url); connection = connectionFactory.createConnection(); if (persistent && clientId != null && clientId.length() > 0 && !"null".equals(clientId)) { connection.setClientID(clientId); } connection.start(); // Create the Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE); // And the Destinations.. if (topic) { destination = session.createTopic(subject); if (replySubject == null || replySubject.equals("")) { replyDest = session.createTemporaryTopic(); } else { replyDest = session.createTopic(replySubject); } } else { destination = session.createQueue(subject); if (replySubject == null || replySubject.equals("")) { replyDest = session.createTemporaryQueue(); } else { replyDest = session.createQueue(replySubject); } } System.out.println("Reply Destination: " + replyDest); // Create the producer producer = session.createProducer(destination); if (persistent) { producer.setDeliveryMode(DeliveryMode.PERSISTENT); } else { producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); } if (timeToLive != 0) { System.out.println("Messages time to live " + timeToLive + " ms"); producer.setTimeToLive(timeToLive); } // Create the reply consumer consumer = session.createConsumer(replyDest); // Start sending reqests. requestLoop(); System.out.println("Done."); // Use the ActiveMQConnection interface to dump the connection // stats. ActiveMQConnection c = (ActiveMQConnection) connection; c.getConnectionStats().dump(new IndentPrinter()); } catch (Exception e) { System.out.println("Caught: " + e); e.printStackTrace(); } finally { try { connection.close(); } catch (Throwable ignore) { } } }
From source file:com.googlecode.fascinator.messaging.EmailNotificationConsumer.java
/** * Start thread running/*w w w . j av a2 s .co m*/ * */ @Override public void run() { try { log.info("Starting {}...", name); // Get a connection to the broker String brokerUrl = globalConfig.getString(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL, "messaging", "url"); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl); connection = connectionFactory.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); consumer = session.createConsumer(session.createQueue(QUEUE_ID)); consumer.setMessageListener(this); // broadcast = session.createTopic(MessagingServices.MESSAGE_TOPIC); producer = session.createProducer(null); producer.setDeliveryMode(DeliveryMode.PERSISTENT); connection.start(); } catch (JMSException ex) { log.error("Error starting message thread!", ex); } }
From source file:com.moss.veracity.core.cluster.jms.UpdateTransmitterJMSImpl.java
private void sendMessage(Object o) { Session session = null;//from w ww. j a v a 2s . com MessageProducer producer = null; try { StringWriter writer = new StringWriter(); Marshaller m = jaxbContext.createMarshaller(); m.marshal(o, writer); String text = writer.getBuffer().toString(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = session.createTopic(UpdateTopic.NAME); producer = session.createProducer(topic); producer.setDeliveryMode(DeliveryMode.PERSISTENT); TextMessage message = session.createTextMessage(text); producer.send(message); producer.close(); session.close(); } catch (Exception ex) { if (producer != null) { try { producer.close(); } catch (JMSException e) { if (log.isErrorEnabled()) { log.error("Failed to close producer after failure", e); } else { ex.printStackTrace(); } } } if (session != null) { try { session.close(); } catch (JMSException e) { if (log.isErrorEnabled()) { log.error("Failed to close session after failure", e); } else { ex.printStackTrace(); } } } throw new RuntimeException("Message transmission failed: " + o, ex); } }
From source file:eu.domibus.submission.jms.BackendJMSImpl.java
private Boolean submitToBackend(final String messageId) { Connection connection;//from w w w . j a va 2 s . com MessageProducer producer; try { connection = this.cf.createConnection(); final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(this.receivingQueue); producer.setDeliveryMode(DeliveryMode.PERSISTENT); final MapMessage resMessage = session.createMapMessage(); this.downloadMessage(messageId, resMessage); producer.send(resMessage); producer.close(); session.close(); connection.close(); } catch (JMSException | ValidationException e) { BackendJMSImpl.LOG.error("", e); return false; } return true; }
From source file:ProducerTool.java
public void run() { Connection connection = null; try {/*w w w .j a v a 2 s.c o m*/ // Create the connection. ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url); connection = connectionFactory.createConnection(); connection.start(); // Create the session Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE); if (topic) { destination = session.createTopic(subject); } else { destination = session.createQueue(subject); } // Create the producer. MessageProducer producer = session.createProducer(destination); if (persistent) { producer.setDeliveryMode(DeliveryMode.PERSISTENT); } else { producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); } if (timeToLive != 0) { producer.setTimeToLive(timeToLive); } // Start sending messages sendLoop(session, producer); System.out.println("[" + this.getName() + "] Done."); synchronized (lockResults) { ActiveMQConnection c = (ActiveMQConnection) connection; System.out.println("[" + this.getName() + "] Results:\n"); c.getConnectionStats().dump(new IndentPrinter()); } } catch (Exception e) { System.out.println("[" + this.getName() + "] Caught: " + e); e.printStackTrace(); } finally { try { connection.close(); } catch (Throwable ignore) { } } }
From source file:com.googlecode.fascinator.common.PythonUtils.java
public PythonUtils(JsonSimpleConfig config) throws PluginException { this.config = config; // Security/*from w w w.j av a2s. c o m*/ String accessControlType = "accessmanager"; access = PluginManager.getAccessManager(accessControlType); access.init(config.toString()); // XML parsing namespaces = new HashMap<String, String>(); DocumentFactory docFactory = new DocumentFactory(); docFactory.setXPathNamespaceURIs(namespaces); saxReader = new SAXReader(docFactory); // Message Queues String brokerUrl = config.getString(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL, "messaging", "url"); connectionFactory = new ActiveMQConnectionFactory(brokerUrl); try { connection = connectionFactory.createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // create single producer for multiple destinations producer = session.createProducer(null); producer.setDeliveryMode(DeliveryMode.PERSISTENT); // cache destinations destinations = new HashMap<String, Destination>(); } catch (JMSException ex) { throw new PluginException(ex); } String access_plugin = config.getString(DEFAULT_ACCESS_PLUGIN, "accesscontrol", "type"); if (access_plugin.indexOf(",") >= 0) { String[] plugin_list = access_plugin.split(","); current_access_plugin = plugin_list[0]; } else { current_access_plugin = access_plugin; } }
From source file:com.oneops.controller.jms.InductorPublisher.java
private MessageProducer newMessageProducer(String queueName) throws JMSException { // Create the session Destination destination = session.createQueue(queueName); // Create the producer. MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.PERSISTENT); logger.info("Created message producer for queue " + queueName); return producer; }
From source file:au.com.redboxresearchdata.fascinator.plugins.JsonHarvestQueueConsumer.java
public void run() { try {//from w ww . ja v a 2s.co m // Get a connection to the broker String brokerUrl = globalConfig.getString(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL, "messaging", "url"); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl); connection = connectionFactory.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); consumer = session.createConsumer(session.createQueue(QUEUE_ID)); consumer.setMessageListener(this); producer = session.createProducer(session.createTopic(EVENT_TOPIC_ID)); producer.setDeliveryMode(DeliveryMode.PERSISTENT); connection.start(); toolChainEntry = globalConfig.getString(DEFAULT_TOOL_CHAIN_QUEUE, "messaging", "toolChainQueue"); failedJsonMap = new HashMap<String, HarvestItem>(); failedJsonList = new ArrayList<String>(); harvestRequests = new HashMap<String, HarvestRequest>(); // registering managed bean... MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName( "au.com.redboxresearchdata.fascinator.plugins:type=JsonHarvestQueue"); mbs.registerMBean(this, mxbeanName); log.info("'{}' is running...", name); } catch (JMSException ex) { log.error("Error starting message thread!", ex); } catch (MalformedObjectNameException e) { log.error("Error configuring MBean, invalid name", e); } catch (InstanceAlreadyExistsException e) { log.error("Error configuring MBean, instance exists.", e); } catch (MBeanRegistrationException e) { log.error("Error registering MBean. ", e); } catch (NotCompliantMBeanException e) { log.error("Error configuring Mbean, non-compliant!", e); } }