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:org.eclipse.smila.connectivity.queue.worker.internal.task.impl.Send.java
/** * {@inheritDoc}// w w w . j a v a 2 s.c om * */ @Override public String[] executeInternal(final TaskExecutionEnv env, final SendType config, final Map<String, Properties> idPropertyMap) throws TaskExecutionException, BlackboardAccessException, RecordFilterNotFoundException { Connection connection = null; Session session = null; try { // get cached connection, if do not cache connections -> socket error when many records pushed connection = env.getServices().getBrokerConnections().getConnection(config, true); connection.start(); session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); final Destination destination = session.createQueue(config.getQueue()); final MessageProducer producer = session.createProducer(destination); if (config.isPersistentDelivery()) { producer.setDeliveryMode(DeliveryMode.PERSISTENT); } else { producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); } final Iterator<Entry<String, Properties>> entries = idPropertyMap.entrySet().iterator(); while (entries.hasNext()) { final Entry<String, Properties> entry = entries.next(); // get message record, optionally a filtered copy. final Record record = createMessageRecord(entry.getKey(), config, env); // prepare queue message. messages are actually sent on session.commit() below. producer.send(createMessage(config, record, entry.getValue(), session)); } // we must commit here so that the message consumer find the correct record version in storages. env.getBlackboard().commit(); env.setCommitRequired(false); // finally send the messages. session.commit(); return idPropertyMap.keySet().toArray(new String[idPropertyMap.size()]); } catch (final Throwable e) { _log.error(msg("Error"), e); rollbackQuietly(session); throw new TaskExecutionException(e); } finally { closeQuietly(session); closeQuietly(connection); } }
From source file:org.frameworkset.mq.RequestDispatcher.java
public void send(int destinationType, String destination_, boolean persistent, int priority, long timeToLive, Message message, Logger step, JMSProperties properties) throws JMSException { if (step != null) step.logBasic("send message to " + destination_ + " assertStarted(),message=" + message); assertStarted();/* w w w . ja va2 s. c o m*/ MessageProducer producer = null; try { Destination destination = null; // boolean isqueue = destinationType == MQUtil.TYPE_QUEUE; // if (isqueue) // { // if(step != null) // step.logBasic("send message to " + destination_ // + " build QUEUE destination"); // destination = session.createQueue(destination_); // if(step != null) // step.logBasic("send message to " + destination_ // + " build QUEUE destination end"); // } // else // { // if(step != null) // step.logBasic("send message to " + destination_ // + " build Topic destination"); // destination = session.createTopic(destination_); // if(step != null) // step.logBasic("send message to " + destination_ // + " build Topic destination end"); // } if (step != null) step.logBasic("send message to " + destination_ + " build destination."); destination = this.connection.createDestination(session, destination_, destinationType); if (step != null) step.logBasic("send message to " + destination_ + " build destination end"); int deliveryMode = persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; if (step != null) step.logBasic("send message to " + destination_ + " this.client.isPersistent =" + persistent); if (step != null) step.logBasic("send message to " + destination + " send started...."); producer = session.createProducer(destination); if (properties != null) MQUtil.initMessage(message, properties); producer.send(message, deliveryMode, priority, timeToLive); if (step != null) step.logBasic("send message to " + destination + " send end...."); if (LOG.isDebugEnabled()) { LOG.debug("Sent! to destination: " + destination + " message: " + message); } } catch (JMSException e) { throw e; } catch (Exception e) { throw new JMSException(e.getMessage()); } finally { if (producer != null) try { producer.close(); } catch (Exception e) { } } }
From source file:org.frameworkset.mq.RequestDispatcher.java
public void send(int destinationType, String destination_, boolean persistent, int priority, long timeToLive, Message message, JMSProperties properties) throws JMSException { LOG.debug("send message to " + destination_ + " assertStarted(),message=" + message); assertStarted();/*from ww w .ja v a 2s .c o m*/ MessageProducer producer = null; try { Destination destination = null; // destinationType = JMSConnectionFactory.evaluateDestinationType(destination_, destinationType); // destination_ = JMSConnectionFactory.evaluateDestination(destination_); // boolean isqueue = destinationType == MQUtil.TYPE_QUEUE; // if (isqueue) // { // LOG.debug("send message to " + destination_ // + " build QUEUE destination"); // destination = session.createQueue(destination_); // LOG.debug("send message to " + destination_ // + " build QUEUE destination end"); // } // else // { // LOG.debug("send message to " + destination_ // + " build Topic destination"); // destination = session.createTopic(destination_); // LOG.debug("send message to " + destination_ // + " build Topic destination end"); // } LOG.debug("send message to " + destination_ + " build destination"); destination = connection.createDestination(session, destination_, destinationType); LOG.debug("send message to " + destination_ + " build destination end."); int deliveryMode = persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; LOG.debug("send message to " + destination_ + " this.client.isPersistent =" + persistent); LOG.debug("send message to " + destination + " send started...."); producer = session.createProducer(destination); if (properties != null) MQUtil.initMessage(message, properties); producer.send(message, deliveryMode, priority, timeToLive); LOG.debug("send message to " + destination + " send end...."); if (LOG.isDebugEnabled()) { LOG.debug("Sent! to destination: " + destination + " message: " + message); } } catch (JMSException e) { throw e; } catch (Exception e) { throw new JMSException(e.getMessage()); } finally { if (producer != null) try { producer.close(); } catch (Exception e) { } } }
From source file:org.frameworkset.mq.RequestDispatcher.java
public void send(String msg, JMSProperties properties) throws JMSException { assertStarted();// w ww . j a v a 2s . co m MessageProducer producer = null; try { Destination destination = null; // if (this.destinationType == MQUtil.TYPE_QUEUE) // { // destination = session.createQueue(this.destination); // } // else // { // destination = session.createTopic(this.destination); // } LOG.debug("send message to " + this.destination + " build destination"); destination = connection.createDestination(session, this.destination, destinationType); LOG.debug("send message to " + this.destination + " build destination end."); int deliveryMode = this.persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; producer = session.createProducer(destination); Message message = createTextMessage(msg); if (properties != null) MQUtil.initMessage(message, properties); producer.send(message, deliveryMode, this.priovity, this.timetolive); if (LOG.isDebugEnabled()) { LOG.debug("Sent! to destination: " + destination + " message: " + message); } } catch (JMSException e) { throw e; } catch (Exception e) { throw new JMSException(e.getMessage()); } finally { if (producer != null) try { producer.close(); } catch (Exception e) { } } }
From source file:org.frameworkset.mq.RequestDispatcher.java
public void send(int destinationType, String destination_, Message message, boolean persistent, int priority, long timeToLive, JMSProperties properties) throws JMSException { assertStarted();/*from www. j a v a2 s. co m*/ MessageProducer producer = null; try { Destination destination = null; // if (destinationType == MQUtil.TYPE_QUEUE) // { // destination = session.createQueue(destination_); // } // else // { // destination = session.createTopic(destination_); // } LOG.debug("send message to " + destination_ + " build destination"); destination = connection.createDestination(session, destination_, destinationType); LOG.debug("send message to " + destination_ + " build destination end."); int deliveryMode = persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; producer = session.createProducer(destination); if (properties != null) MQUtil.initMessage(message, properties); producer.send(message, deliveryMode, priority, timeToLive); if (LOG.isDebugEnabled()) { LOG.debug("Sent! to destination: " + destination + " message: " + message); } message = null; } catch (JMSException e) { throw e; } catch (Exception e) { throw new JMSException(e.getMessage()); } finally { if (producer != null) try { producer.close(); } catch (Exception e) { } } }
From source file:org.genemania.broker.Worker.java
public synchronized void onMessage(Message msg) { if (msg instanceof TextMessage) { String responseBody = ""; try {// www . j a v a2 s .com // extract message data Queue queue = (Queue) msg.getJMSDestination(); requestMessage = (TextMessage) msg; LOG.debug("new " + msg.getJMSType() + " message received on queue " + queue.getQueueName() + "[correlation id: " + msg.getJMSCorrelationID() + "]"); responseMessage = session.createTextMessage(); responseMessage.setJMSDestination(requestMessage.getJMSReplyTo()); responseMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT); responseMessage.setJMSCorrelationID(msg.getJMSCorrelationID()); // invoke engine if (queue.getQueueName().equalsIgnoreCase(mqRequestsQueueName)) { if (MessageType.RELATED_GENES.equals(MessageType.fromCode(msg.getJMSType()))) { RelatedGenesRequestMessage data = RelatedGenesRequestMessage .fromXml(requestMessage.getText()); RelatedGenesResponseMessage response = getRelatedGenes(data); responseBody = response.toXml(); } else if (MessageType.TEXT2NETWORK.equals(MessageType.fromCode(msg.getJMSType()))) { UploadNetworkRequestMessage data = UploadNetworkRequestMessage .fromXml(requestMessage.getText()); UploadNetworkResponseMessage response = uploadNetwork(data); responseBody = response.toXml(); } else if (MessageType.PROFILE2NETWORK.equals(MessageType.fromCode(msg.getJMSType()))) { LOG.warn("invoking engine.profile2network: not implemented"); } else { LOG.warn("Unknown jms type: " + msg.getJMSType()); } } processedMessages++; } catch (JMSException e) { LOG.error(e); try { responseBody = buildErrorMessage(e.getMessage(), MessageType.fromCode(msg.getJMSType())); } catch (JMSException x) { LOG.error(x); } } finally { if ((requestMessage != null) && (responseMessage != null)) { try { if (StringUtils.isNotEmpty(responseBody)) { responseMessage.setText(responseBody); LOG.debug("Responding to " + responseMessage.getJMSDestination() + ", msg id " + responseMessage.getJMSCorrelationID() + ", response body size " + (int) responseBody.length()); responseHandler.send(responseMessage.getJMSDestination(), responseMessage); } else { responseBody = buildErrorMessage("Empty response body detected", MessageType.fromCode(msg.getJMSType())); } } catch (JMSException e) { LOG.error("JMS Exception: " + e.getMessage()); try { responseBody = buildErrorMessage(e.getMessage(), MessageType.fromCode(msg.getJMSType())); responseHandler.send(responseMessage); } catch (JMSException e1) { LOG.error("JMS Exception", e1); } } } else { if (requestMessage == null) { LOG.error("request message is null"); } if (responseMessage == null) { LOG.error("response message is null"); } } } } else { LOG.warn("Unknown message type: " + msg); } LOG.info("successfully processed messages: " + processedMessages); }
From source file:org.genemania.connector.JmsEngineConnector.java
@Cacheable(cacheName = "searchResultsCache", keyGenerator = @KeyGenerator(name = "StringCacheKeyGenerator")) public RelatedGenesWebResponseDto getRelatedGenes(final RelatedGenesWebRequestDto dto) throws ApplicationException { final String rgcid = String.valueOf(System.currentTimeMillis()); RelatedGenesWebResponseDto ret = new RelatedGenesWebResponseDto(); jmsTemplate.send(requestQueue, new MessageCreator() { public TextMessage createMessage(Session session) throws JMSException { LOG.debug("sending GetRelatedGenesMessage request to " + requestQueue.getQueueName()); RelatedGenesRequestMessage request = BrokerUtils.dto2msg(dto); TextMessage ret = session.createTextMessage(request.toXml()); ret.setJMSDeliveryMode(DeliveryMode.PERSISTENT); ret.setJMSType(MessageType.RELATED_GENES.getCode()); replyQueue = session.createTemporaryQueue(); ret.setJMSReplyTo(replyQueue); ret.setJMSCorrelationID(rgcid); LOG.debug("getRelatedGenes waiting for reply on " + replyQueue.getQueueName()); return ret; }//from w w w . j a v a 2 s . c om }); sentMessages++; Message response; try { response = jmsTemplate.receive(replyQueue); receivedMessages++; if (response == null) { LOG.error("getRelatedGenes JMS response is null"); } else if (!response.getJMSCorrelationID().equals(rgcid)) { LOG.error("JMS response id does not match request, sent " + rgcid + ", recieved " + response.getJMSCorrelationID() + ", dropping response."); } else { LOG.debug("getRelatedGenes reply received"); String responseBody = ((TextMessage) response).getText(); if (StringUtils.isNotEmpty(responseBody)) { RelatedGenesResponseMessage responseMessage = RelatedGenesResponseMessage.fromXml(responseBody); LOG.debug("finished fromXml"); LOG.debug("num attributes in response message: " + responseMessage.getAttributes().size()); if (responseMessage.getErrorCode() == 0) { // friendlyPrintNetworks("networks in response message: ", // responseMessage.getNetworks()); // friendlyPrintCategories("categories in response message: ", // responseMessage.getAnnotations()); RelatedGenesWebResponseDto hollowResponseDto = BrokerUtils.msg2dto(responseMessage); LOG.debug("finished msg2dto"); ret = load(hollowResponseDto); LOG.debug("finished hollowResponseDto"); } else { LOG.error(responseMessage.getErrorMessage()); appErrors++; throw new ApplicationException(responseMessage.getErrorMessage(), responseMessage.getErrorCode()); } } else { LOG.error("getRelatedGenes empty response body"); } } processedMessages++; } catch (JMSException e) { LOG.error("getRelatedGenes JMSException: " + e.getMessage()); errors++; throw new ApplicationException(Constants.ERROR_CODES.APPLICATION_ERROR); } catch (DataStoreException e) { LOG.error("getRelatedGenes DataStoreException: " + e.getMessage()); errors++; throw new ApplicationException(Constants.ERROR_CODES.DATA_ERROR); } finally { LOG.debug("messages sent/received/processed/errors: " + sentMessages + "/" + receivedMessages + "/" + processedMessages + "/" + errors); // updateStats(); } LOG.debug("getRelatedGenes request processing completed"); return ret; }
From source file:org.genemania.connector.JmsEngineConnector.java
public UploadNetworkWebResponseDto uploadNetwork(final UploadNetworkWebRequestDto dto) throws ApplicationException { final String uncid = String.valueOf(System.currentTimeMillis()); UploadNetworkWebResponseDto ret = new UploadNetworkWebResponseDto(); jmsTemplate.send(requestQueue, new MessageCreator() { public TextMessage createMessage(Session session) throws JMSException { LOG.debug("sending UploadnetworkMessage request to " + requestQueue.getQueueName()); UploadNetworkRequestMessage request = BrokerUtils.dto2msg(dto); TextMessage ret = session.createTextMessage(request.toXml()); ret.setJMSDeliveryMode(DeliveryMode.PERSISTENT); ret.setJMSType(MessageType.TEXT2NETWORK.getCode()); replyQueue = session.createTemporaryQueue(); ret.setJMSReplyTo(replyQueue); ret.setJMSCorrelationID(uncid); LOG.debug("uploadNetwork waiting for reply on " + replyQueue.getQueueName()); sentMessages++;//from ww w. jav a 2 s . c o m return ret; } }); Message response; try { response = jmsTemplate.receive(replyQueue); receivedMessages++; if (response.getJMSCorrelationID().equals(uncid)) { LOG.debug("uploadNetwork reply received"); if (response != null) { String responseBody = ((TextMessage) response).getText(); if (StringUtils.isNotEmpty(responseBody)) { UploadNetworkResponseMessage responseMessage = UploadNetworkResponseMessage .fromXml(responseBody); if (responseMessage.getErrorCode() == 0) { ret = BrokerUtils.msg2dto(responseMessage); } else { throw new ApplicationException(responseMessage.getErrorMessage(), responseMessage.getErrorCode()); } } else { LOG.error("uploadNetwork empty response body"); } } else { LOG.error("uploadNetwork JMS response is null"); } } processedMessages++; } catch (JMSException e) { errors++; throw new ApplicationException(Constants.ERROR_CODES.APPLICATION_ERROR); } finally { LOG.debug("messages sent/received/processed/appErrors/errors: " + sentMessages + "/" + receivedMessages + "/" + processedMessages + "/" + appErrors + "/" + errors); // updateStats(); } LOG.debug("uploadNetwork request processing completed"); return ret; }
From source file:org.jboss.processFlow.knowledgeService.AsyncBAMProducerPool.java
BAMProducerWrapper(Session sessionObj, Destination dQueue) throws JMSException { this.sessionObj = sessionObj; this.producerObj = sessionObj.createProducer(dQueue); this.producerObj.setDeliveryMode(DeliveryMode.PERSISTENT); }
From source file:org.mot.common.mq.ActiveMQFactory.java
/** * Create a new message producer onto a particular destination * /*from ww w . jav a 2s . c o m*/ * @param destination - destination queue/topic object * @return the message producer object */ public MessageProducer createMessageProducer(String channel, long ttl, boolean persistent) { Destination destination = createDestination(channel); MessageProducer msg = null; try { msg = session.createProducer(destination); msg.setTimeToLive(ttl); if (persistent) { msg.setDeliveryMode(DeliveryMode.PERSISTENT); } else { msg.setDeliveryMode(DeliveryMode.NON_PERSISTENT); } } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } return msg; }