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.facetime.communication.activemq.AmqConsumer.java
public void send(Destination destination, Message message, boolean persistent, int priority, long timeToLive) throws JMSException { int deliveryMode = persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; getProducer().send(destination, message, deliveryMode, priority, timeToLive); if (LOG.isDebugEnabled()) { LOG.debug("Sent! to destination: " + destination + " message: " + message); }// ww w. ja v a 2 s . c o m }
From source file:eu.domibus.submission.jms.BackendJMSImpl.java
/** * This method checks for pending messages received by another gateway and processes them to a JMS destination * * @param ctx/* w ww . j av a 2 s . c o m*/ */ public void executeInternal(final JobExecutionContext ctx) { try { final Collection<String> ids = this.messageRetriever.listPendingMessages(); if (!ids.isEmpty() || ids.size() > 0) { final String[] messageIds = ids.toArray(new String[ids.size()]); Connection connection; MessageProducer producer; connection = this.cf.createConnection(); for (final String messageId : messageIds) { 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(); } else { BackendJMSImpl.LOG.debug("No pending messages to send"); } } catch (final JMSException | ValidationException ex) { BackendJMSImpl.LOG.error(ex); } }
From source file:com.googlecode.fascinator.portal.HouseKeeper.java
/** * Start thread running// w ww . j av a 2s . c om * */ @Override public void run() { openLog(); try { globalConfig = new JsonSimpleConfig(); // 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(); // Sessions are not thread safe, to send a message outside // of the onMessage() callback you need another session. cSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); pSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = cSession.createQueue(QUEUE_ID); consumer = cSession.createConsumer(destination); consumer.setMessageListener(this); // Producer destHouseKeeping = pSession.createQueue(QUEUE_ID); producer = pSession.createProducer(null); producer.setDeliveryMode(DeliveryMode.PERSISTENT); connection.start(); // Database prep work try { // Look for our table checkTable(NOTIFICATIONS_TABLE); // Sync in-memory actions to database syncActionList(); // Purge any old 'block' entries since we just (re)started for (UserAction ua : actions) { if (ua.block) { removeAction(ua.id); } } } catch (SQLException ex) { log.error("Error during database preparation:", ex); } log.debug("Derby house keeping database online!"); // Quartz Scheduler try { scheduler = StdSchedulerFactory.getDefaultScheduler(); scheduler.start(); quartzScheduling(); } catch (SchedulerException ex) { log.error("Scheduled failed to start: ", ex); } // Start our callback timer log.info("Starting callback timer. Timeout = {}s", timeout); timer = new Timer("HouseKeeping", true); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { onTimeout(); } }, 0, timeout * 1000); } catch (IOException ex) { log.error("Unable to read config!", ex); } catch (JMSException ex) { log.error("Error starting message thread!", ex); } closeLog(); }
From source file:com.chinamobile.bcbsp.comm.ProducerTool.java
/** Run method of Thread. */ public final void run() { while (true) { while (this.idle) { if (this.completed) { return; }/*from www .j a va 2s . com*/ if (this.noMoreMessagesFlag) { this.superStepCounter++; this.noMoreMessagesFlag = false; // LOG.info("Test Progress: from " + (this.superStepCounter - 1) + // " to " + this.superStepCounter); } try { Thread.sleep(this.sleepTime); } catch (InterruptedException e) { LOG.error("[ProducerTool] to " + this.hostNameAndPort + " has been interrupted for ", e); return; } } if (this.hostNameAndPort == null) { LOG.error("Destination hostname is null."); return; } if (this.messageQueue == null) { LOG.error("Message queue for ProducerTool is null."); return; } this.messageCount = 0; this.connectTime = 0; this.sendTime = 0; while (true) { if (this.reconnectCount == ProducerTool.RECONNECTTHRESHOLD) { break; } try { if (this.newHostNameAndPort) { // Should create new connection. if (connection != null) { try { connection.close(); } catch (Throwable ignore) { LOG.warn("[ConsumerTool] run connection " + ignore); } } long start = System.currentTimeMillis(); /** Clock */ // Make the destination broker's url. this.url = "tcp://" + this.hostNameAndPort; // Create the connection. // ActiveMQConnectionFactory connectionFactory = new // ActiveMQConnectionFactory( // user, password, url); BSPActiveMQConnFactory connectionFactory = new BSPActiveMQConnFactoryImpl(); connectionFactory.activeMQConnFactoryMethod(url); connectionFactory.setCopyMessageOnSend(false); connection = connectionFactory.createConnection(); connection.start(); // Create the session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE); this.connectTime += (System.currentTimeMillis() - start); /* Clock */ this.newHostNameAndPort = false; start = System.currentTimeMillis(); /* Clock */ destination = session.createQueue(subject); // Create the producer. producer = session.createProducer(destination); if (persistent) { producer.setDeliveryMode(DeliveryMode.PERSISTENT); } else { producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); } if (timeToLive != 0) { producer.setTimeToLive(timeToLive); } this.connectTime += (System.currentTimeMillis() - start); } // Start sending messages sendLoopOptimistic(session, producer); this.idle = true; break; } catch (Exception e) { this.reconnectCount++; if (this.reconnectCount == 1) { LOG.error("[ProducerTool] to " + this.hostNameAndPort + " caught: ", e); } LOG.info("[ProducerTool] to " + this.hostNameAndPort + " is reconnecting for " + this.reconnectCount + "th time."); LOG.info("---------------- Memory Info ------------------"); MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage(); long used = memoryUsage.getUsed(); long committed = memoryUsage.getCommitted(); LOG.info("[JVM Memory used] = " + used / MB_SIZE + "MB"); LOG.info("[JVM Memory committed] = " + committed / MB_SIZE + "MB"); LOG.info("-----------------------------------------------"); try { Thread.sleep(this.sleepTime); } catch (InterruptedException e1) { LOG.error("[ProducerTool] caught: ", e1); } } } LOG.info("[ProducerTool] to " + this.hostNameAndPort + " has sent " + this.messageCount + " messages totally! (with " + this.messageQueue.size() + " messages lost!)"); this.sender.addConnectTime(this.connectTime); /* Clock */ this.sender.addSendTime(this.sendTime); /* Clock */ if (this.reconnectCount == ProducerTool.RECONNECTTHRESHOLD) { LOG.info("[ProducerTool] to " + this.hostNameAndPort + " has reconnected for " + this.reconnectCount + " times but failed!"); this.isFailed = true; break; } } }
From source file:org.logicblaze.lingo.jms.JmsClientInterceptor.java
public boolean isPersistentDelivery() { return producerConfig.getDeliveryMode() == DeliveryMode.PERSISTENT; }
From source file:org.logicblaze.lingo.jms.JmsClientInterceptor.java
/** * Sets the delivery mode to be persistent or non-persistent. *//*from w w w. j ava2s . com*/ public void setPersistentDelivery(boolean persistent) { producerConfig.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT); }
From source file:com.ccc.ccm.client.JMSTemplateAutowired.java
/** * Set whether message delivery should be persistent or non-persistent, * specified as boolean value ("true" or "false"). This will set the delivery * mode accordingly, to either "PERSISTENT" (1) or "NON_PERSISTENT" (2). * <p>Default it "true" aka delivery mode "PERSISTENT". * @see #setDeliveryMode(int)/*from w w w .j a v a2 s . c o m*/ * @see javax.jms.DeliveryMode#PERSISTENT * @see javax.jms.DeliveryMode#NON_PERSISTENT */ public void setDeliveryPersistent(boolean deliveryPersistent) { this.deliveryMode = (deliveryPersistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT); }
From source file:com.mirth.connect.connectors.jms.JmsReceiverTests.java
private void putMessagesInDestination(Destination destination, int numMessages) throws Exception { if (numMessages > 0) { MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.PERSISTENT); logger.debug("Putting " + numMessages + " messages into destination"); for (int i = 0; i < numMessages; i++) { TextMessage message = session.createTextMessage(TEST_HL7_MESSAGE); message.setIntProperty("messageNumber", i); producer.send(message);/*from w w w . ja v a2 s.c o m*/ } } }
From source file:hermes.browser.HermesBrowser.java
public int getSendPersistence() { return DeliveryMode.PERSISTENT; }
From source file:com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingWorker.java
private static String formatHeaders(Message message) { Destination dest = null;/* w w w .j av a 2 s . c o m*/ int delMode = 0; long expiration = 0; Time expTime = null; int priority = 0; String msgID = null; long timestamp = 0; Time timestampTime = null; String correlID = null; Destination replyTo = null; boolean redelivered = false; String type = null; StringBuilder sb = new StringBuilder(); try { try { dest = message.getJMSDestination(); sb.append(" JMSDestination: "); sb.append(dest); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSDestination header\n", e); } try { delMode = message.getJMSDeliveryMode(); if (delMode == DeliveryMode.NON_PERSISTENT) { sb.append(" JMSDeliveryMode: non-persistent\n"); } else if (delMode == DeliveryMode.PERSISTENT) { sb.append(" JMSDeliveryMode: persistent\n"); } else { sb.append(" JMSDeliveryMode: neither persistent nor non-persistent; error\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSDeliveryMode header\n", e); } try { expiration = message.getJMSExpiration(); if (expiration != 0) { expTime = new Time(expiration); sb.append(" JMSExpiration: "); sb.append(expTime); sb.append("\n"); } else { sb.append(" JMSExpiration: 0\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSExpiration header\n", e); } try { priority = message.getJMSPriority(); sb.append(" JMSPriority: "); sb.append(priority); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSPriority header\n", e); } try { msgID = message.getJMSMessageID(); sb.append(" JMSMessageID: "); sb.append(msgID); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSMessageID header\n", e); } try { timestamp = message.getJMSTimestamp(); if (timestamp != 0) { timestampTime = new Time(timestamp); sb.append(" JMSTimestamp: "); sb.append(timestampTime); sb.append("\n"); } else { sb.append(" JMSTimestamp: 0\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSTimestamp header\n", e); } try { correlID = message.getJMSCorrelationID(); sb.append(" JMSCorrelationID: "); sb.append(correlID); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSCorrelationID header\n", e); } try { replyTo = message.getJMSReplyTo(); sb.append(" JMSReplyTo: "); sb.append(replyTo); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSReplyTo header\n", e); } try { redelivered = message.getJMSRedelivered(); sb.append(" JMSRedelivered: "); sb.append(redelivered); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSRedelivered header\n", e); } try { type = message.getJMSType(); sb.append(" JMSType: "); sb.append(type); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSType header\n", e); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMS headers\n", e); } return sb.toString(); }