コード例 #1
1
  @Test(invocationCount = 5, successPercentage = 19)
  public void topicConduit() throws Exception {
    String topicName =
        "JmsByteArrayTransportTest-topicConduit-"
            + System.getProperty("user.name")
            + "-"
            + System.currentTimeMillis();
    ConnectionFactory cf = ActiveMQTestUtils.createTestConnectionFactory();
    JmsTemplate jmsTemplate = new JmsTemplate();
    jmsTemplate.setConnectionFactory(cf);
    jmsTemplate.setPubSubDomain(true);

    JmsByteArrayMessageSender messageSender = new JmsByteArrayMessageSender(topicName, jmsTemplate);
    CollectingByteArrayMessageReceiver collectingReceiver =
        new CollectingByteArrayMessageReceiver();
    JmsByteArrayMessageDispatcher messageDispatcher =
        new JmsByteArrayMessageDispatcher(collectingReceiver);

    DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
    container.setConnectionFactory(cf);
    container.setMessageListener(messageDispatcher);
    container.setDestinationName(topicName);
    container.setPubSubDomain(true);
    container.afterPropertiesSet();
    container.start();

    Random random = new Random();
    byte[] randomBytes = new byte[1024];
    random.nextBytes(randomBytes);

    while (!container.isRunning()) {
      Thread.sleep(10l);
    }
    // TODO: this is a hack.  The context doesn't seem to have always set up the consumer completely
    // yet
    Thread.sleep(500l);

    messageSender.send(randomBytes);
    long startTime = System.currentTimeMillis();
    while (collectingReceiver.getMessages().isEmpty()) {
      Thread.sleep(10l);
      if ((System.currentTimeMillis() - startTime) > TIMEOUT) {
        fail("Did not receive a message in " + (TIMEOUT / 1000) + " seconds.");
      }
    }
    s_logger.debug(
        "topicConduit message received {}ms before timeout limit",
        TIMEOUT - (System.currentTimeMillis() - startTime));
    assertEquals(1, collectingReceiver.getMessages().size());
    byte[] receivedBytes = collectingReceiver.getMessages().get(0);
    assertEquals(randomBytes.length, receivedBytes.length);
    for (int i = 0; i < randomBytes.length; i++) {
      assertEquals(randomBytes[i], receivedBytes[i]);
    }

    container.stop();
    container.destroy();
  }
コード例 #2
0
 @Bean(destroyMethod = "destroy")
 public DefaultMessageListenerContainer jmsContainer() {
   final DefaultMessageListenerContainer jmsContainer = new DefaultMessageListenerContainer();
   jmsContainer.setDestination(destination());
   jmsContainer.setConnectionFactory(amqConnectionFactory());
   jmsContainer.setMessageListener(messageListener());
   jmsContainer.setConcurrency("5-10");
   jmsContainer.setReceiveTimeout(5000);
   jmsContainer.afterPropertiesSet();
   return jmsContainer;
 }
コード例 #3
0
 @Bean
 public DefaultMessageListenerContainer dlmsRequestsMessageListenerContainer() {
   final DefaultMessageListenerContainer messageListenerContainer =
       new DefaultMessageListenerContainer();
   messageListenerContainer.setConnectionFactory(this.pooledConnectionFactory());
   messageListenerContainer.setDestination(this.dlmsRequestsQueue());
   messageListenerContainer.setConcurrentConsumers(
       Integer.parseInt(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_DLMS_REQUESTS_CONCURRENT_CONSUMERS)));
   messageListenerContainer.setMaxConcurrentConsumers(
       Integer.parseInt(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_DLMS_REQUESTS_MAX_CONCURRENT_CONSUMERS)));
   messageListenerContainer.setMessageListener(this.dlmsRequestsMessageListener);
   messageListenerContainer.setSessionTransacted(true);
   return messageListenerContainer;
 }
コード例 #4
0
ファイル: MessagingConfig.java プロジェクト: wernerb/Platform
 @Bean(name = "domainAdminIncomingOsgpCoreRequestsMessageListenerContainer")
 public DefaultMessageListenerContainer incomingOsgpCoreRequestsMessageListenerContainer() {
   final DefaultMessageListenerContainer messageListenerContainer =
       new DefaultMessageListenerContainer();
   messageListenerContainer.setConnectionFactory(this.pooledConnectionFactory());
   messageListenerContainer.setDestination(this.incomingOsgpCoreRequestsQueue());
   messageListenerContainer.setConcurrentConsumers(
       Integer.parseInt(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_INCOMING_OSGP_CORE_REQUESTS_CONCURRENT_CONSUMERS)));
   messageListenerContainer.setMaxConcurrentConsumers(
       Integer.parseInt(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_INCOMING_OSGP_CORE_REQUESTS_MAX_CONCURRENT_CONSUMERS)));
   messageListenerContainer.setMessageListener(this.incomingOsgpCoreRequestMessageListener);
   messageListenerContainer.setSessionTransacted(true);
   return messageListenerContainer;
 }
コード例 #5
0
    // set up the jms queue
    void init(TournamentService host) {
      log.info("Server URL: " + serverUrl + ", queue: " + queueName);

      // Can't set this earlier, need the params from visualizerService
      ActiveMQConnectionFactory amqFactory =
          (ActiveMQConnectionFactory) connectionFactory.getTargetConnectionFactory();
      amqFactory.setBrokerURL(serverUrl);

      // register host as listener
      container = new DefaultMessageListenerContainer();
      container.setConnectionFactory(connectionFactory);
      container.setDestinationName(queueName);
      container.setMessageListener(host);
      container.setTaskExecutor(taskExecutor);
      container.afterPropertiesSet();
      container.start();

      connectionOpen = true;
    }
コード例 #6
0
  private void run(String topicName) {
    ActiveMQConnectionFactory activeMqFactory =
        new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL);
    CachingConnectionFactory factory = new CachingConnectionFactory(activeMqFactory);

    DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
    container.setConnectionFactory(factory);
    container.setDestination(new ActiveMQTopic(topicName));
    container.setMessageListener(new LoggerMessageListener());
    container.start();
    container.initialize();

    try {
      TimeUnit.MINUTES.sleep(1);
    } catch (InterruptedException ex) {
      LOGGER.warn("Thread ended with exception", ex);
    }

    LOGGER.info("Done");
  }
コード例 #7
0
  @Override
  protected AbstractMessageListenerContainer createListenerContainer() throws Exception {
    // Use DefaultMessageListenerContainer as it supports reconnects (see CAMEL-3193)
    // request-reply listener container should not allow quick-stop so we can keep listening for
    // reply messages
    DefaultMessageListenerContainer answer =
        new DefaultJmsMessageListenerContainer(endpoint, false);

    answer.setDestinationName("temporary");
    answer.setDestinationResolver(destResolver);
    answer.setAutoStartup(true);
    if (endpoint.getMaxMessagesPerTask() >= 0) {
      answer.setMaxMessagesPerTask(endpoint.getMaxMessagesPerTask());
    }
    answer.setIdleConsumerLimit(endpoint.getIdleConsumerLimit());
    answer.setIdleTaskExecutionLimit(endpoint.getIdleTaskExecutionLimit());
    answer.setMessageListener(this);
    answer.setPubSubDomain(false);
    answer.setSubscriptionDurable(false);
    answer.setConcurrentConsumers(endpoint.getConcurrentConsumers());
    if (endpoint.getMaxConcurrentConsumers() > 0) {
      answer.setMaxConcurrentConsumers(endpoint.getMaxConcurrentConsumers());
    }
    answer.setConnectionFactory(endpoint.getConnectionFactory());
    // we use CACHE_CONSUMER by default to cling to the consumer as long as we can, since we can
    // only consume
    // msgs from the JMS Connection that created the temp destination in the first place
    if (endpoint.getReplyToCacheLevelName() != null) {
      if ("CACHE_NONE".equals(endpoint.getReplyToCacheLevelName())) {
        throw new IllegalArgumentException(
            "ReplyToCacheLevelName cannot be CACHE_NONE when using temporary reply queues. The value must be either CACHE_CONSUMER, or CACHE_SESSION");
      }
      answer.setCacheLevelName(endpoint.getReplyToCacheLevelName());
    } else {
      answer.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
    }
    String clientId = endpoint.getClientId();
    if (clientId != null) {
      clientId += ".CamelReplyManager";
      answer.setClientId(clientId);
    }

    // we cannot do request-reply over JMS with transaction
    answer.setSessionTransacted(false);

    // other optional properties
    answer.setExceptionListener(
        new TemporaryReplyQueueExceptionListener(destResolver, endpoint.getExceptionListener()));

    if (endpoint.getErrorHandler() != null) {
      answer.setErrorHandler(endpoint.getErrorHandler());
    } else {
      answer.setErrorHandler(
          new DefaultSpringErrorHandler(
              TemporaryQueueReplyManager.class,
              endpoint.getErrorHandlerLoggingLevel(),
              endpoint.isErrorHandlerLogStackTrace()));
    }
    if (endpoint.getReceiveTimeout() >= 0) {
      answer.setReceiveTimeout(endpoint.getReceiveTimeout());
    }
    if (endpoint.getRecoveryInterval() >= 0) {
      answer.setRecoveryInterval(endpoint.getRecoveryInterval());
    }
    if (endpoint.getTaskExecutor() != null) {
      if (log.isDebugEnabled()) {
        log.debug(
            "Using custom TaskExecutor: {} on listener container: {}",
            endpoint.getTaskExecutor(),
            answer);
      }
      answer.setTaskExecutor(endpoint.getTaskExecutor());
    }

    // setup a bean name which is used by Spring JMS as the thread name
    // use the name of the request destination
    String name = "TemporaryQueueReplyManager[" + endpoint.getDestinationName() + "]";
    answer.setBeanName(name);

    if (answer.getConcurrentConsumers() > 1) {
      // log that we are using concurrent consumers
      log.info(
          "Using {}-{} concurrent consumers on {}",
          new Object[] {answer.getConcurrentConsumers(), answer.getMaxConcurrentConsumers(), name});
    }
    return answer;
  }
コード例 #8
0
ファイル: JmsConsumer.java プロジェクト: chicagozer/rheosoft
 protected void createMessageListenerContainer() throws Exception {
   listenerContainer = getEndpoint().createMessageListenerContainer();
   getEndpoint().configureListenerContainer(listenerContainer, this);
   listenerContainer.setMessageListener(getEndpointMessageListener());
 }
コード例 #9
0
  @Test(invocationCount = 5, successPercentage = 19)
  public void requestConduit() throws Exception {
    String topicName =
        "JmsByteArrayTransportTest-requestConduit-"
            + System.getProperty("user.name")
            + "-"
            + System.currentTimeMillis();
    ConnectionFactory cf = ActiveMQTestUtils.createTestConnectionFactory();
    JmsTemplate jmsTemplate = new JmsTemplate();
    jmsTemplate.setConnectionFactory(cf);
    jmsTemplate.setPubSubDomain(true);
    jmsTemplate.setReceiveTimeout(5000l);

    final Random random = new Random();
    final byte[] responseBytes = new byte[512];
    random.nextBytes(responseBytes);

    JmsByteArrayRequestSender requestSender = new JmsByteArrayRequestSender(topicName, jmsTemplate);
    JmsByteArrayRequestDispatcher requestDispatcher =
        new JmsByteArrayRequestDispatcher(
            new ByteArrayRequestReceiver() {
              @Override
              public byte[] requestReceived(byte[] message) {
                return responseBytes;
              }
            });

    DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
    container.setConnectionFactory(cf);
    container.setMessageListener(requestDispatcher);
    container.setDestinationName(topicName);
    container.setPubSubDomain(true);
    container.afterPropertiesSet();
    container.start();

    byte[] randomBytes = new byte[1024];
    random.nextBytes(randomBytes);

    while (!container.isRunning()) {
      Thread.sleep(10l);
    }

    CollectingByteArrayMessageReceiver collectingReceiver =
        new CollectingByteArrayMessageReceiver();
    requestSender.sendRequest(randomBytes, collectingReceiver);
    long startTime = System.currentTimeMillis();
    while (collectingReceiver.getMessages().isEmpty()) {
      Thread.sleep(10l);
      if ((System.currentTimeMillis() - startTime) > TIMEOUT) {
        fail("Did not receive a response in " + (TIMEOUT / 1000) + " seconds.");
      }
    }
    s_logger.debug(
        "requestConduit message received {}ms before timeout limit",
        TIMEOUT - (System.currentTimeMillis() - startTime));
    assertEquals(1, collectingReceiver.getMessages().size());
    byte[] receivedBytes = collectingReceiver.getMessages().get(0);
    assertEquals(responseBytes.length, receivedBytes.length);
    for (int i = 0; i < responseBytes.length; i++) {
      assertEquals(responseBytes[i], receivedBytes[i]);
    }

    container.stop();
    container.destroy();
  }