List of usage examples for javax.jms Message acknowledge
void acknowledge() throws JMSException;
From source file:com.espertech.esperio.regression.adapter.SupportJMSReceiver.java
public Message receiveMessage() throws JMSException { Message message = jmsTemplate.receive(); if (message != null) { message.acknowledge(); }/* w ww.j av a 2s . c o m*/ return message; }
From source file:io.datalayer.activemq.consumer.SpringConsumer.java
public void onMessage(Message message) { super.onMessage(message); try {//from w ww . ja v a 2 s . co m message.acknowledge(); } catch (JMSException e) { LOG.error("Failed to acknowledge: " + e, e); } }
From source file:com.espertech.esperio.jms.SpringJMSTemplateInputAdapter.java
public void onMessage(Message message) { try {/*from w w w . ja va 2 s . com*/ if (stateManager.getState() == AdapterState.DESTROYED) { log.warn( ".onMessage Event message not sent to engine, state of adapter is destroyed, message ack'd"); message.acknowledge(); return; } if (epServiceProviderSPI == null) { log.warn( ".onMessage Event message not sent to engine, service provider not set yet, message ack'd"); message.acknowledge(); return; } synchronized (message) { Object theEvent = jmsMessageUnmarshaller.unmarshal(epServiceProviderSPI.getEventAdapterService(), message); if (theEvent != null) { if (theEvent instanceof Node) { epServiceProviderSPI.getEPRuntime().sendEvent((Node) theEvent); } else { epServiceProviderSPI.getEPRuntime().sendEvent(theEvent); } } else { if (log.isWarnEnabled()) { log.warn(".onMessage Event object not sent to engine: " + message.getJMSMessageID()); } } message.acknowledge(); } } catch (JMSException ex) { throw new EPException(ex); } catch (EPException ex) { log.error(".onMessage exception", ex); if (stateManager.getState() == AdapterState.STARTED) { stop(); } else { destroy(); } } }
From source file:org.mule.modules.jmsbatchmessaging.JmsBatchMessagingConnector.java
/** * Acknowledge messages in a batch// ww w . ja va2 s. com * <p/> * {@sample.xml ../../../doc/jms-batch-messaging-connector.xml.sample * jms-batch-messaging:acknowledge} * * @param muleMessage the current MuleMessage * @param message The individual message to batch. If this isn't set the entire batch is acknowledged. Note that messages are held in the "messages" inboundProperty. * @throws Exception Comment for Exception */ @Processor @Inject public void acknowledge(MuleMessage muleMessage, @Optional Message message) throws Exception { if (message != null) { message.acknowledge(); } else { List<Message> messages = muleMessage.getInboundProperty("messages"); for (Message eachMessage : messages) { eachMessage.acknowledge(); } } }
From source file:uk.co.jassoft.markets.crawler.CrawlerListener.java
@Override @JmsListener(destination = "Crawler", concurrency = "5") public void onMessage(final Message message) { if (message instanceof TextMessage) { final TextMessage textMessage = (TextMessage) message; try {//from w w w. j a v a2 s . com message.acknowledge(); final Story story = mapper.readValue(textMessage.getText(), Story.class); Source source = sourceRepository.findOne(story.getParentSource()); if (source.isDisabled()) { LOG.info("Source [{}] is Disabled", source.getName()); final Link link = linkService.findOneByLink(story.getUrl().toString()); if (link != null) { linkService.delete(link); } return; } if (SourceUtils.matchesExclusion(source.getExclusionList(), story.getUrl().toString())) { LOG.info("Story Link Matches Exclusion for Source [{}]", source.getName()); final Link link = linkService.findOneByLink(story.getUrl().toString()); if (link != null) { linkService.delete(link); } return; } if (isbaseURL(source.getUrls(), story.getUrl().toString())) { SourceUrl currentSourceUrl = source.getUrls().parallelStream() .filter(sourceUrl -> sourceUrl.getUrl().equals(story.getUrl().toString())).findFirst() .get(); if (!currentSourceUrl.isEnabled() || (currentSourceUrl.getDisabledUntil() != null && currentSourceUrl.getDisabledUntil().after(new Date()))) { LOG.info("Source URL [{}] is Disabled", currentSourceUrl.getUrl()); final Link link = linkService.findOneByLink(story.getUrl().toString()); if (link != null) { linkService.delete(link); } return; } } try (InputStream inputStream = network.read(story.getUrl().toString(), "GET", !isbaseURL(source.getUrls(), story.getUrl().toString()))) { Document doc = Jsoup.parse(inputStream, "UTF-8", story.getUrl().toString()); Elements links = doc.select("a[href]"); doc = null; LOG.debug("Found [{}] Links in [{}]", links.size(), story.getUrl().toString()); AtomicInteger newLinkCount = new AtomicInteger(0); links.stream().map(link -> { String linkHref = link.attr("abs:href"); if (linkHref.contains("#")) linkHref = linkHref.substring(0, linkHref.indexOf("#")); return new ImmutablePair<String, Element>(linkHref, link); }).filter(isNotGlobalExclusion()).filter(isValidUrl(source)) .filter(doesNotMatchExclusion(source)).filter(isNewLink(linkService, storyRepository)) .forEach(link -> { try { LOG.debug("{} - {}", link.getKey(), link.getValue().text()); Story storyFound = new Story(link.getValue().text(), new URL(link.getKey()), new Date(), story.getParentSource()); crawlLink(storyFound); newLinkCount.incrementAndGet(); Story existingStory = storyRepository .findOneByUrl(storyFound.getUrl().toString()); if (existingStory != null) return; if (link.getKey().getBytes().length < 1000) { storyRepository.save(storyFound); collectStory(storyFound.getId()); linkService.save(new Link(link.getKey())); } else { LOG.warn("Link too long to persist. Not Persisting. {} - {}", link.getKey(), link.getValue().text()); } } catch (final Exception exception) { LOG.error("Error found with Link {} - {}", link.getKey(), link.getValue().text() + ": " + exception.getLocalizedMessage()); } }); if (newLinkCount.get() > 0) { LOG.info("Found [{}] New Links in [{}]", newLinkCount.get(), story.getUrl().toString()); } links = null; } catch (IOException exception) { LOG.warn("IOException Crawling Link [{}] - [{}]", story.getUrl().toString(), exception.getMessage()); sourceErrorRepository.save(new SourceError(source.getId(), new Date(), story.getUrl().toString(), null, exception.getMessage())); return; } if (isbaseURL(source.getUrls(), story.getUrl().toString())) { SourceUrl currentSourceUrl = source.getUrls().parallelStream() .filter(sourceUrl -> sourceUrl.getUrl().equals(story.getUrl().toString())).findFirst() .get(); currentSourceUrl.setLastCrawled(new Date()); currentSourceUrl.setPendingCrawl(false); if (currentSourceUrl.getCrawlInterval() == null) { currentSourceUrl.setCrawlInterval(60); } mongoTemplate.updateFirst( Query.query(Criteria.where("id").is(source.getId()).and("urls.url") .is(story.getUrl().toString())), new Update().set("urls.$", currentSourceUrl), Source.class); } } catch (IOException exception) { LOG.warn(exception.getLocalizedMessage()); return; } catch (final Exception exception) { LOG.error(exception.getLocalizedMessage(), exception); throw new RuntimeException(exception); } } }
From source file:com.zotoh.maedr.device.JmsIO.java
private void onMessage(Message msg) { try {/* w ww.j av a 2 s . c o m*/ dispatch(new JmsEvent(this, msg)); msg = null; } catch (Exception e) { tlog().error("", e); } finally { if (msg != null) try { msg.acknowledge(); } catch (Exception ee) { } } }
From source file:com.chakray.chilcano.wso2.rabbitmq.message.store.RabbitMQConsumer.java
public MessageContext receive() { boolean error; JMSException exception;//from w ww.j a va2 s. c o m if (!checkConnection()) { if (!reconnect()) { if (logger.isDebugEnabled()) { logger.debug(getId() + " cannot receive message from store. Cannot reconnect."); } return null; } else { logger.info(getId() + " reconnected to store."); isReceiveError = false; } } if (!checkConnection()) { if (logger.isDebugEnabled()) { logger.debug(getId() + " cannot receive message from store."); } return null; } try { Message message = consumer.receive(3000); if (message == null) { return null; } if (!(message instanceof ObjectMessage)) { logger.warn(getId() + ". Did not receive a javax.jms.ObjectMessage"); message.acknowledge(); // TODO: return null; } ObjectMessage msg = (ObjectMessage) message; String messageId = msg.getStringProperty(Constants.OriginalMessageID); if (!(msg.getObject() instanceof StorableMessage)) { logger.warn(getId() + ". Did not receive a valid message."); message.acknowledge(); return null; } StorableMessage storableMessage = (StorableMessage) msg.getObject(); org.apache.axis2.context.MessageContext axis2Mc = store.newAxis2Mc(); MessageContext synapseMc = store.newSynapseMc(axis2Mc); synapseMc = MessageConverter.toMessageContext(storableMessage, axis2Mc, synapseMc); updateCache(message, synapseMc, messageId, false); if (logger.isDebugEnabled()) { logger.debug( getId() + " Received MessageId:" + messageId + " priority:" + message.getJMSPriority()); } return synapseMc; } catch (JMSException e) { error = true; exception = e; } if (error) { if (!isReceiveError) { logger.error( getId() + " cannot receive message from store. Error:" + exception.getLocalizedMessage());//, exception); } updateCache(null, null, "", true); cleanup(); return null; } return null; }
From source file:org.apache.synapse.message.store.impl.jms.JmsConsumer.java
public MessageContext receive() { boolean error; JMSException exception;/*from w w w .ja v a 2 s . c o m*/ if (!checkConnection()) { if (!reconnect()) { if (logger.isDebugEnabled()) { logger.debug(getId() + " cannot receive message from store. Cannot reconnect."); } return null; } else { logger.info(getId() + " reconnected to store."); isReceiveError = false; } } if (!checkConnection()) { if (logger.isDebugEnabled()) { logger.debug(getId() + " cannot receive message from store."); } return null; } try { Message message = consumer.receive(1); if (message == null) { return null; } if (!(message instanceof ObjectMessage)) { logger.warn(getId() + ". Did not receive a javax.jms.ObjectMessage"); message.acknowledge(); // TODO: return null; } ObjectMessage msg = (ObjectMessage) message; String messageId = msg.getStringProperty(Constants.OriginalMessageID); if (!(msg.getObject() instanceof StorableMessage)) { logger.warn(getId() + ". Did not receive a valid message."); message.acknowledge(); return null; } StorableMessage storableMessage = (StorableMessage) msg.getObject(); org.apache.axis2.context.MessageContext axis2Mc = store.newAxis2Mc(); MessageContext synapseMc = store.newSynapseMc(axis2Mc); synapseMc = MessageConverter.toMessageContext(storableMessage, axis2Mc, synapseMc); updateCache(message, synapseMc, messageId, false); if (logger.isDebugEnabled()) { logger.debug( getId() + " Received MessageId:" + messageId + " priority:" + message.getJMSPriority()); } return synapseMc; } catch (JMSException e) { error = true; exception = e; } if (error) { if (!isReceiveError) { logger.error( getId() + " cannot receive message from store. Error:" + exception.getLocalizedMessage());//, exception); } updateCache(null, null, "", true); cleanup(); return null; } return null; }
From source file:org.codehaus.stomp.jms.StompSession.java
public Message receiveFromJms(String destinationName, Map headers) throws JMSException, ProtocolException, NamingException { long ttl = getTimeToLive(headers); log.trace("Consuming message - ttl=" + ttl); Destination destination = convertDestination(destinationName, true); MessageConsumer consumer = session.createConsumer(destination); Message message; if (ttl > 0) { message = consumer.receive(ttl); } else {//from w w w.j a v a 2 s . com message = consumer.receive(); } if (message != null) { // As this is a dequeue, automatically acknowledge the message message.acknowledge(); } consumer.close(); log.trace("Received message: " + message); return message; }
From source file:com.oneops.antenna.jms.AntennaListener.java
/** * (non-Javadoc)// www . j av a2 s . co m * * @see javax.jms.MessageListener#onMessage(javax.jms.Message) */ public void onMessage(Message msg) { msgs.mark(); Context tc = msgTime.time(); try { NotificationMessage notify = null; if (msg instanceof TextMessage) { try { notify = parseMsg((TextMessage) msg); } catch (JsonParseException e) { logger.error("Got the bad message, not a valid json format - \n" + ((TextMessage) msg).getText() + "\n" + e.getMessage()); msg.acknowledge(); } } else if (msg instanceof ObjectMessage) { notify = (NotificationMessage) ((ObjectMessage) msg).getObject(); } if (notify != null) { logger.debug("Notification message received: " + notify.getText()); if (notify.getTimestamp() == 0) { notify.setTimestamp(System.currentTimeMillis()); } dispatcher.dispatch(notify); } msg.acknowledge(); } catch (Exception ex) { logger.error("Can't process the notification message.", ex); } finally { tc.stop(); } }