Java Code Examples for org.apache.activemq.ActiveMQConnectionFactory#setUseAsyncSend()

The following examples show how to use org.apache.activemq.ActiveMQConnectionFactory#setUseAsyncSend() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetworkBrokerDetachTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: NetworkLoadTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected Connection createConnection(int brokerId) throws JMSException {
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:" + (60000 + brokerId));
   connectionFactory.setOptimizedMessageDispatch(true);
   connectionFactory.setCopyMessageOnSend(false);
   connectionFactory.setUseCompression(false);
   connectionFactory.setDispatchAsync(true);
   connectionFactory.setUseAsyncSend(false);
   connectionFactory.setOptimizeAcknowledge(false);
   connectionFactory.setWatchTopicAdvisories(false);
   ActiveMQPrefetchPolicy qPrefetchPolicy = new ActiveMQPrefetchPolicy();
   qPrefetchPolicy.setQueuePrefetch(100);
   qPrefetchPolicy.setTopicPrefetch(1000);
   connectionFactory.setPrefetchPolicy(qPrefetchPolicy);
   connectionFactory.setAlwaysSyncSend(true);
   return connectionFactory.createConnection();
}
 
Example 3
Source File: InactiveQueueTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
   super.setUp();
   broker = new BrokerService();

   // broker.setPersistenceAdapter(new KahaPersistenceAdapter(new File
   // ("TEST_STUFD")));
     /*
      * JournalPersistenceAdapterFactory factory = new
      * JournalPersistenceAdapterFactory();
      * factory.setDataDirectoryFile(broker.getDataDirectory());
      * factory.setTaskRunnerFactory(broker.getTaskRunnerFactory());
      * factory.setUseJournal(false); broker.setPersistenceFactory(factory);
      */
   broker.addConnector(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL);
   broker.start();
   connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_BROKER_URL);
     /*
      * Doesn't matter if you enable or disable these, so just leaving them
      * out for this test case connectionFactory.setAlwaysSessionAsync(true);
      * connectionFactory.setAsyncDispatch(true);
      */
   connectionFactory.setUseAsyncSend(true);
}
 
Example 4
Source File: InactiveDurableTopicTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
   super.setUp();
   broker = new BrokerService();

   //broker.setPersistenceAdapter(new KahaPersistenceAdapter());
     /*
      * JournalPersistenceAdapterFactory factory = new
      * JournalPersistenceAdapterFactory();
      * factory.setDataDirectoryFile(broker.getDataDirectory());
      * factory.setTaskRunnerFactory(broker.getTaskRunnerFactory());
      * factory.setUseJournal(false); broker.setPersistenceFactory(factory);
      */
   broker.addConnector(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL);
   broker.start();
   connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_BROKER_URL);
     /*
      * Doesn't matter if you enable or disable these, so just leaving them
      * out for this test case connectionFactory.setAlwaysSessionAsync(true);
      * connectionFactory.setAsyncDispatch(true);
      */
   connectionFactory.setUseAsyncSend(true);
}
 
Example 5
Source File: SpringJmsConfig.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Bean
public ConnectionFactory connectionFactory() {
    ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
    activeMQConnectionFactory.setUseAsyncSend(true);
    activeMQConnectionFactory.setAlwaysSessionAsync(true);
    activeMQConnectionFactory.setStatsEnabled(true);
    return new CachingConnectionFactory(activeMQConnectionFactory);
}
 
Example 6
Source File: SpringJmsConfig.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Bean
public ConnectionFactory connectionFactory() {
    ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
    activeMQConnectionFactory.setUseAsyncSend(true);
    activeMQConnectionFactory.setAlwaysSessionAsync(true);
    activeMQConnectionFactory.setStatsEnabled(true);
    return new CachingConnectionFactory(activeMQConnectionFactory);
}
 
Example 7
Source File: FailoverStaticNetworkTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
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.setDispatchAsync(false);
   connectionFactory.setUseAsyncSend(false);
   connectionFactory.setOptimizeAcknowledge(false);
   connectionFactory.setAlwaysSyncSend(true);
   return connectionFactory;
}
 
Example 8
Source File: ConnectionFactory.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
public Connection newConnection(String brokerURL, ExceptionListener exceptionListener) throws JMSException {
        String finalBrokerURL = toUrl(brokerURL);

        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(finalBrokerURL);

        // to speed things up; don't wait till it is on the socket buffer.
        // http://activemq.apache.org/async-sends.html
        connectionFactory.setUseAsyncSend(true);

        // authentication stuff.
        connectionFactory.setUserName(username);
        connectionFactory.setPassword(password);
        // we want to consume the least amount of resources possible. And there will be very low volume traffic.

        connectionFactory.setMaxThreadPoolSize(MAX_THREAD_POOL_SIZE);
        //
//        connectionFactory.setRejectedTaskHandler(new  RejectedExecutionHandler() {
//            public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
//                try {
//                    executor.getQueue().put(r);
//                } catch (InterruptedException var4) {
//                    throw new RejectedExecutionException(var4);
//                }
//            }
//        });

        Connection connection = connectionFactory.createConnection();
        connection.setExceptionListener(exceptionListener);
        connection.start();
        return connection;
    }
 
Example 9
Source File: SensorPublisher.java    From oneops with Apache License 2.0 4 votes vote down vote up
/**
 * Inits the.
 *
 * @throws JMSException the jMS exception
 */
public void init() throws JMSException {
    Properties properties = new Properties();
    try {
        properties.load(this.getClass().getResourceAsStream("/sink.properties"));
    } catch (IOException e) {
        logger.error("got: " + e.getMessage());
    }

    user = properties.getProperty("amq.user");
    password = System.getenv("KLOOPZ_AMQ_PASS");


    if (password == null) {
        throw new JMSException("missing KLOOPZ_AMQ_PASS env var");
    }

    AMQConnectorURI connectStringGenerator = new AMQConnectorURI();
    connectStringGenerator.setHost("opsmq");
    connectStringGenerator.setProtocol("tcp");
    connectStringGenerator.setPort(61616);
    connectStringGenerator.setTransport("failover");
    connectStringGenerator.setDnsResolve(true);
    connectStringGenerator.setKeepAlive(true);
    HashMap<String, String> transportOptions = new HashMap<>();
    transportOptions.put("initialReconnectDelay", "1000");
    transportOptions.put("startupMaxReconnectAttempts", mqConnectionStartupRetries);
    transportOptions.put("timeout", mqConnectionTimeout);
    transportOptions.put("useExponentialBackOff", "false");
    connectStringGenerator.setTransportOptions(transportOptions);
    url = connectStringGenerator.build();

    showParameters();

    // Create the connection.
    ActiveMQConnectionFactory amqConnectionFactory = new ActiveMQConnectionFactory(user, password, url);
    amqConnectionFactory.setUseAsyncSend(true);
    PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(amqConnectionFactory);
    pooledConnectionFactory.setMaxConnections(amqConnectionPoolSize);
    pooledConnectionFactory.setIdleTimeout(10000);

    for (int i = 0; i < poolsize; i++) {
        JmsTemplate producerTemplate = new JmsTemplate(pooledConnectionFactory);
        producerTemplate.setSessionTransacted(false);
        int shard = i + 1;
        Destination perfin = new org.apache.activemq.command.ActiveMQQueue(queueBase + "-" + shard);
        producerTemplate.setDefaultDestination(perfin);
        producerTemplate.setDeliveryPersistent(false);
        producers[i] = producerTemplate;
    }


}
 
Example 10
Source File: LoadTester.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
protected ConnectionFactory createConnectionFactory() throws URISyntaxException, IOException {
   ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getServer().getConnectURI());
   factory.setUseAsyncSend(true);
   return factory;
}