protected PollingConsumer getPollingConsumer() throws JMSException { try { if (pollingConsumer == null) { pollingConsumer = endpoint.createPollingConsumer(); pollingConsumer.start(); } return pollingConsumer; } catch (JMSException e) { throw e; } catch (Exception e) { throw JMSExceptionSupport.create(e); } }
protected PollingConsumer getPollingConsumer() throws JMSException { try { if (pollingConsumer == null) { pollingConsumer = endpoint.createPollingConsumer(); pollingConsumer.start(); } return pollingConsumer; } catch (JMSException e) { throw e; } catch (Exception e) { throw JMSExceptionSupport.create(e); } }
protected PollingConsumer getConsumer(final String uri) { if (!knownURIs.contains(uri)) { knownURIs.add(uri); Endpoint endpoint = contextFactory.getCamelContext().getEndpoint(uri); PollingConsumer pollingConsumer = null; try { pollingConsumer = endpoint.createPollingConsumer(); consumerMap.put(uri, pollingConsumer); pollingConsumer.start(); } catch (Exception ex) { LOG.error("Unexpected error in Consumer creation ", ex); } return pollingConsumer; } else { return consumerMap.get(uri); } } }
@Transactional @Test public void testMessageSendToConsumerQueueRemoteId() throws Exception { Status status = new Status(); status.setUserId(10); statusDAO.save(status); Endpoint mockEndpoint = this.context.getEndpoint(properties.getProperty("activemq.destination")); PollingConsumer consumer = mockEndpoint.createPollingConsumer(); producerTemplate.sendBodyAndHeader(source, "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><example><remoteid>10</remoteid></example>","disableReplyTo","true"); Status savedStatus = consumer.receive(100).getIn().getBody(Status.class); logger.info("savedStatus "+savedStatus.getID()+" "+savedStatus.getUserId()); assertNotNull(savedStatus); }
@Test public void configureExcange() throws Exception { PollingConsumer pollingConsumer = null; try { CamelContext context = new DefaultCamelContext(); Endpoint endpoint = context.getEndpoint("imaps://imap.gmail.com?username=" + mailId + "&password=" + password + "&delete=false&peek=false&unseen=true&consumer.delay=60000&closeFolder=false&disconnect=false"); // options unseen=true, will only poll unread mails //Polling an END point pollingConsumer = endpoint.createPollingConsumer(); pollingConsumer.start(); pollingConsumer.getEndpoint().createExchange(); Exchange exchange = pollingConsumer.receive(60000); while (exchange != null) { process(exchange); //each time "pollingConsumer" will poll 1 mail at a time exchange = pollingConsumer.receive(60000); } } catch (Exception e) { e.printStackTrace(); } }