Esempio n. 1
0
  public void testConnectionFactory() throws Exception {
    // Create sample connection factory
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
    factory.setDispatchAsync(true);
    factory.setBrokerURL("vm://test");
    factory.setClientID("test");
    factory.setCopyMessageOnSend(false);
    factory.setDisableTimeStampsByDefault(true);
    factory.setObjectMessageSerializationDefered(true);
    factory.setOptimizedMessageDispatch(false);
    factory.setPassword("pass");
    factory.setUseAsyncSend(true);
    factory.setUseCompression(true);
    factory.setUseRetroactiveConsumer(true);
    factory.setUserName("user");
    factory.getPrefetchPolicy().setQueuePrefetch(777);
    factory.getRedeliveryPolicy().setMaximumRedeliveries(15);
    factory.getRedeliveryPolicy().setBackOffMultiplier((short) 32);

    // Create reference
    Reference ref = JNDIReferenceFactory.createReference(factory.getClass().getName(), factory);

    // Get object created based on reference
    ActiveMQConnectionFactory temp;
    JNDIReferenceFactory refFactory = new JNDIReferenceFactory();
    temp = (ActiveMQConnectionFactory) refFactory.getObjectInstance(ref, null, null, null);

    // Check settings
    assertEquals(factory.isDispatchAsync(), temp.isDispatchAsync());
    assertEquals(factory.getBrokerURL(), temp.getBrokerURL());
    assertEquals(factory.getClientID(), temp.getClientID());
    assertEquals(factory.isCopyMessageOnSend(), temp.isCopyMessageOnSend());
    assertEquals(factory.isDisableTimeStampsByDefault(), temp.isDisableTimeStampsByDefault());
    assertEquals(
        factory.isObjectMessageSerializationDefered(), temp.isObjectMessageSerializationDefered());
    assertEquals(factory.isOptimizedMessageDispatch(), temp.isOptimizedMessageDispatch());
    assertEquals(factory.getPassword(), temp.getPassword());
    assertEquals(factory.isUseAsyncSend(), temp.isUseAsyncSend());
    assertEquals(factory.isUseCompression(), temp.isUseCompression());
    assertEquals(factory.isUseRetroactiveConsumer(), temp.isUseRetroactiveConsumer());
    assertEquals(factory.getUserName(), temp.getUserName());
    assertEquals(
        factory.getPrefetchPolicy().getQueuePrefetch(),
        temp.getPrefetchPolicy().getQueuePrefetch());
    assertEquals(
        factory.getRedeliveryPolicy().getMaximumRedeliveries(),
        temp.getRedeliveryPolicy().getMaximumRedeliveries());
    assertEquals(
        factory.getRedeliveryPolicy().getBackOffMultiplier(),
        temp.getRedeliveryPolicy().getBackOffMultiplier());
  }
Esempio n. 2
0
  private ActiveMQConnectionFactory createFactory() {

    // connect to the embedded broker defined above
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(Info.BROKER_DEFAULT);

    // tuned for performances
    // http://activemq.apache.org/performance-tuning.html
    factory.setUseAsyncSend(true);
    factory.setOptimizeAcknowledge(true);
    factory.setAlwaysSessionAsync(true);
    factory.setObjectMessageSerializationDefered(true);
    factory.setCopyMessageOnSend(false);

    return factory;
  }
 protected ConnectionFactory createConnectionFactory(final BrokerService broker) throws Exception {
   String url = broker.getTransportConnectors().get(0).getServer().getConnectURI().toString();
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
   connectionFactory.setOptimizedMessageDispatch(true);
   connectionFactory.setCopyMessageOnSend(false);
   connectionFactory.setUseCompression(false);
   connectionFactory.setDispatchAsync(false);
   connectionFactory.setUseAsyncSend(false);
   connectionFactory.setOptimizeAcknowledge(false);
   connectionFactory.setWatchTopicAdvisories(true);
   ActiveMQPrefetchPolicy qPrefetchPolicy = new ActiveMQPrefetchPolicy();
   qPrefetchPolicy.setQueuePrefetch(100);
   qPrefetchPolicy.setTopicPrefetch(1000);
   connectionFactory.setPrefetchPolicy(qPrefetchPolicy);
   connectionFactory.setAlwaysSyncSend(true);
   return connectionFactory;
 }
Esempio n. 4
0
  public CentralListener(int inactiveTimeout) throws Exception {

    // listener for centralListener queue in clientEngineBroker
    ActiveMQConnectionFactory connectionFactory =
        new ActiveMQConnectionFactory(
            "failover:(tcp://192.168.208.247:8888?keepAlive=true&tcpNoDelay=true&socketBufferSize=131072&ioBufferSize=16384&trace=false&soTimeout=180000&connectionTimeout=60000&wireFormat.maxInactivityDuration="
                + inactiveTimeout
                + ")?initialReconnectDelay=10&maxReconnectDelay=360000&maxReconnectAttempts=120");
    connectionFactory.setCopyMessageOnSend(false);
    Connection connection = connectionFactory.createConnection();
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue("CENTER");
    MessageConsumer consumer = session.createConsumer(destination);

    consumer.setMessageListener(this);
  }