當前位置: 首頁>>代碼示例>>Java>>正文


Java JmsTemplate.setDefaultDestination方法代碼示例

本文整理匯總了Java中org.springframework.jms.core.JmsTemplate.setDefaultDestination方法的典型用法代碼示例。如果您正苦於以下問題:Java JmsTemplate.setDefaultDestination方法的具體用法?Java JmsTemplate.setDefaultDestination怎麽用?Java JmsTemplate.setDefaultDestination使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.jms.core.JmsTemplate的用法示例。


在下文中一共展示了JmsTemplate.setDefaultDestination方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkActiveMQJMSProtocol

import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
public String checkActiveMQJMSProtocol(String messageAsString,
                                       String url) throws JMSException {
    ActiveMQConnectionFactory activeMQConnectionFactory =
            new ActiveMQConnectionFactory(String.format("tcp://%s", url));
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory(activeMQConnectionFactory);
    JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    Destination destination = new ActiveMQQueue("myQueue");
    jmsTemplate.setDefaultDestination(destination);
    jmsTemplate.send(destination, t -> {
        TextMessage message = t.createTextMessage(messageAsString);
        return message;
    });
    TextMessage receivedMessage = (TextMessage) jmsTemplate.receive(destination);
    return receivedMessage.getText();
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:16,代碼來源:CheckBrokerConnectionUtils.java

示例2: init

import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
/**
 * 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;
    }


}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:58,代碼來源:SensorPublisher.java

示例3: getJmsTemplate

import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
public JmsTemplate getJmsTemplate() {
    JmsTemplate jmsTemplate = new JmsTemplate();

    jmsTemplate.setConnectionFactory(mqConnectionFactory.getFactory());
    jmsTemplate.setDefaultDestination(new ActiveMQQueue(queueName));
    jmsTemplate.setReceiveTimeout(600);
    jmsTemplate.setMessageConverter(messageConverter);

    return jmsTemplate;
}
 
開發者ID:phpdragon,項目名稱:JavaSamples,代碼行數:11,代碼來源:MqProducer.java


注:本文中的org.springframework.jms.core.JmsTemplate.setDefaultDestination方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。