锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲成av人片,亚洲一区二区三区高清不卡,成人av综合网http://www.aygfsteel.com/paulwong/category/51879.htmlzh-cnMon, 12 Jul 2021 15:33:35 GMTMon, 12 Jul 2021 15:33:35 GMT60鏋勫緩ARTEMIS闆嗙兢http://www.aygfsteel.com/paulwong/archive/2021/06/30/435912.htmlpaulwongpaulwongWed, 30 Jun 2021 08:33:00 GMThttp://www.aygfsteel.com/paulwong/archive/2021/06/30/435912.htmlhttp://www.aygfsteel.com/paulwong/comments/435912.htmlhttp://www.aygfsteel.com/paulwong/archive/2021/06/30/435912.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435912.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435912.html闃呰鍏ㄦ枃

paulwong 2021-06-30 16:33 鍙戣〃璇勮
]]>
!!娣卞叆浜嗚ВActiveMQ錛?/title><link>http://www.aygfsteel.com/paulwong/archive/2021/04/01/435839.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Thu, 01 Apr 2021 08:36:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2021/04/01/435839.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/435839.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2021/04/01/435839.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/435839.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/435839.html</trackback:ping><description><![CDATA[<a target="_blank">https://my.oschina.net/u/1388595/blog/4545503</a><br /><br /><img src ="http://www.aygfsteel.com/paulwong/aggbug/435839.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2021-04-01 16:36 <a href="http://www.aygfsteel.com/paulwong/archive/2021/04/01/435839.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鍦⊿PRING BOOT涓嬌鐢ㄥJMS CONNECTIONhttp://www.aygfsteel.com/paulwong/archive/2020/03/19/435278.htmlpaulwongpaulwongThu, 19 Mar 2020 01:45:00 GMThttp://www.aygfsteel.com/paulwong/archive/2020/03/19/435278.htmlhttp://www.aygfsteel.com/paulwong/comments/435278.htmlhttp://www.aygfsteel.com/paulwong/archive/2020/03/19/435278.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435278.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435278.html
ActiveMQConnectionFactoryFactory.java
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.List;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQConnectionFactoryCustomizer;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQProperties;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQProperties.Packages;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;


/**
 * Factory to create a {
@link ActiveMQConnectionFactory} instance from properties defined
 * in {
@link SecondaryActiveMQProperties}.
 *
 * 
@author Phillip Webb
 * 
@author Venil Noronha
 
*/
class ActiveMQConnectionFactoryFactory {

    private static final String DEFAULT_EMBEDDED_BROKER_URL = "vm://localhost?broker.persistent=false";

    private static final String DEFAULT_NETWORK_BROKER_URL = "tcp://localhost:61616";

    private final ActiveMQProperties properties;

    private final List<ActiveMQConnectionFactoryCustomizer> factoryCustomizers;

    ActiveMQConnectionFactoryFactory(ActiveMQProperties properties,
            List<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
        Assert.notNull(properties, "Properties must not be null");
        this.properties = properties;
        this.factoryCustomizers = (factoryCustomizers != null) ? factoryCustomizers : Collections.emptyList();
    }

    public <T extends ActiveMQConnectionFactory> T createConnectionFactory(Class<T> factoryClass) {
        try {
            return doCreateConnectionFactory(factoryClass);
        }
        catch (Exception ex) {
            throw new IllegalStateException("Unable to create " + "ActiveMQConnectionFactory", ex);
        }
    }

    private <T extends ActiveMQConnectionFactory> T doCreateConnectionFactory(Class<T> factoryClass) throws Exception {
        T factory = createConnectionFactoryInstance(factoryClass);
        if (this.properties.getCloseTimeout() != null) {
            factory.setCloseTimeout((intthis.properties.getCloseTimeout().toMillis());
        }
        factory.setNonBlockingRedelivery(this.properties.isNonBlockingRedelivery());
        if (this.properties.getSendTimeout() != null) {
            factory.setSendTimeout((intthis.properties.getSendTimeout().toMillis());
        }
        Packages packages = this.properties.getPackages();
        if (packages.getTrustAll() != null) {
            factory.setTrustAllPackages(packages.getTrustAll());
        }
        if (!packages.getTrusted().isEmpty()) {
            factory.setTrustedPackages(packages.getTrusted());
        }
        customize(factory);
        return factory;
    }

    private <T extends ActiveMQConnectionFactory> T createConnectionFactoryInstance(Class<T> factoryClass)
            throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
        String brokerUrl = determineBrokerUrl();
        String user = this.properties.getUser();
        String password = this.properties.getPassword();
        if (StringUtils.hasLength(user) && StringUtils.hasLength(password)) {
            return factoryClass.getConstructor(String.class, String.class, String.class).newInstance(user, password,
                    brokerUrl);
        }
        return factoryClass.getConstructor(String.class).newInstance(brokerUrl);
    }

    private void customize(ActiveMQConnectionFactory connectionFactory) {
        for (ActiveMQConnectionFactoryCustomizer factoryCustomizer : this.factoryCustomizers) {
            factoryCustomizer.customize(connectionFactory);
        }
    }

    String determineBrokerUrl() {
        if (this.properties.getBrokerUrl() != null) {
            return this.properties.getBrokerUrl();
        }
        if (this.properties.isInMemory()) {
            return DEFAULT_EMBEDDED_BROKER_URL;
        }
        return DEFAULT_NETWORK_BROKER_URL;
    }
}

TwinJmsConnectionFactoryConfiguration.java
import java.util.stream.Collectors;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.messaginghub.pooled.jms.JmsPoolConnectionFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.jms.JmsPoolConnectionFactoryFactory;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQConnectionFactoryCustomizer;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;


@Configuration
@Profile({"local"})
public class TwinJmsConnectionFactoryConfiguration {

    @Bean
    @ConfigurationProperties(prefix = "spring.activemq.primary")
    public ActiveMQProperties primaryActiveMQProperties() {
        return new ActiveMQProperties();
    }
    
    @Bean(destroyMethod = "stop")
    @Primary
    @ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "true")
    public JmsPoolConnectionFactory connectionFactory(ActiveMQProperties primaryActiveMQProperties,
            ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(primaryActiveMQProperties,
                factoryCustomizers.orderedStream().collect(Collectors.toList()))
                .createConnectionFactory(ActiveMQConnectionFactory.class);
        return new JmsPoolConnectionFactoryFactory(primaryActiveMQProperties.getPool())
                .createPooledConnectionFactory(connectionFactory);
    }
    
    ////////////////////////////////////////////////////////////////////////////////
    @Bean
    @ConfigurationProperties(prefix = "spring.activemq.sescond")
    public ActiveMQProperties sescondActiveMQProperties() {
        return new ActiveMQProperties();
    }
    
    @Bean(destroyMethod = "stop")
    @ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "true")
    public JmsPoolConnectionFactory sescondPooledJmsConnectionFactory(ActiveMQProperties sescondActiveMQProperties,
            ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(sescondActiveMQProperties,
                factoryCustomizers.orderedStream().collect(Collectors.toList()))
                .createConnectionFactory(ActiveMQConnectionFactory.class);
        return new JmsPoolConnectionFactoryFactory(sescondActiveMQProperties.getPool())
                .createPooledConnectionFactory(connectionFactory);
    }
    
}




paulwong 2020-03-19 09:45 鍙戣〃璇勮
]]>
Which is better: PooledConnectionFactory or CachingConnectionFactory?http://www.aygfsteel.com/paulwong/archive/2020/03/19/435277.htmlpaulwongpaulwongThu, 19 Mar 2020 01:37:00 GMThttp://www.aygfsteel.com/paulwong/archive/2020/03/19/435277.htmlhttp://www.aygfsteel.com/paulwong/comments/435277.htmlhttp://www.aygfsteel.com/paulwong/archive/2020/03/19/435277.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435277.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435277.htmlFrom here:

The difference between the PooledConnectionFactory and the CachingConnectionFactory is a difference in implementation. Below are some of the characteristics that differ between them:

  • Although both the PooledConnectionFactory and the CachingConnectionFactory state that they each pool connections, sessions and producers, the PooledConnectionFactory does not actually create a cache of multiple producers. It simply uses a singleton pattern to hand out a single cached producer when one is requested. Whereas the CachingConnectionFactory actually creates a cache containing multiple producers and hands out one producer from the cache when one is requested.

  • The PooledConnectionFactory is built on top of the Apache Commons Pool project for pooling JMS sessions. This allows some additional control over the pool because there are features in Commons Pool that are not being used by the PooledConnectionFactory. These additional features include growing the pool size instead of blocking, throwing an exception when the pool is exhausted, etc. You can utilize these features by creating your own Commons Pool GenericObjectPool using your own customized settings and then handing that object to the PooledConnectionFactory via the setPoolFactory method. See the following for additional info: http://commons.apache.org/pool/api-1.4/org/apache/commons/pool/impl/GenericObjectPoolFactory.html

  • The CachingConnectionFactory has the ability to also cache consumers. Just need to take care when using this feature so that you know the consumers are cached according to the rules noted in the blog post.

  • But most importantly, the CachingConnectionFactory will work with any JMS compliant MOM. It only requires a JMS connection factory. This is important if you are using more than one MOM vendor which is very common in enterprise organizations (this is mainly due to legacy and existing projects). The important point is that the CachingConnectionFactory works very well with many different MOM implementations, not only ActiveMQ.

From here:

  • If you have clustered ActiveMQs, and use failover transport it has been reported that CachingConnectionFactory is not a right choice.

  • The problem I’m having is that if one box goes down, we should start sending messages on the other, but it seems to still be using the old connection (every send times out). If I restart the program, it’ll connect again and everything works. Source: Autoreconnect problem with ActiveMQ and CachingConnectionFactory

  • The problem is that cached connections to the failed ActiveMQ was still in use and that created the problem for the user. Now, the choice for this scenario is PooledConnectionFactory.

  • If you’re using ActiveMQ today, and chances are that you may switch to some other broker (JBoss MQ, WebSphere MQ) in future, do not use PooledConnectionFactory, as it tightly couples your code to ActiveMQ.



paulwong 2020-03-19 09:37 鍙戣〃璇勮
]]>
Setting up ActiveMQ for HA-Load Balancehttp://www.aygfsteel.com/paulwong/archive/2019/11/04/434897.htmlpaulwongpaulwongMon, 04 Nov 2019 08:14:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/11/04/434897.htmlhttp://www.aygfsteel.com/paulwong/comments/434897.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/11/04/434897.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/434897.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/434897.html
In a typical enterprise applications, we often need messaging and asynchronous processing.
To satisfy this need, we need a reliable as well as scalable messaging infrastructure. In currently available messaging infrastructures Apache ActiveMQ stands out in terms of features and simplicity.

Apache ActiveMQ comes with lot of features in built and also provides a way to configure or tweak as per the needs of an application.

In this post , we will explore how to enable network of activeMQ brokers so that we achieve HA(High Availability) as well as load balance between consumers & producers.

I carried out  my experiment on local machine with ACtiveMQ 5.8.0, but this can be easily upgraded to latest versions of ActiveMQ viz. 5.10.0

To have network of brokers, we need multiple brokers. So, I changed tcp and admin ports of brokers so that I can run multiple brokers on single machine.

To get brief background on network of broker, please visit this link

In this post we will setup below topology, we will mix failover and NOB to get work done,

1. Producer1 is configured to send messages to broker3 with failover to broker2
2. Producer2 is configured to send messages to broker2 with failover to broker3
3. Broker3, Broker2 are networked with Broker1as below


4. Broker1 is connected with broker4 with NOB.
5. Make sure you enable "advisorySupport" on the broker, which is essential for transparent routing of messages across brokers.
Dry Run:
1. Producer1 sends messages to queue "input.q" on broker3, where there are no active consumers, but it see subscriptions from broker1
2. Broker1 and broker 4 are has consumers which are looking at "input.q".
3. When broker3 receives a message it forwards it to broker1, as its in networked and has active consumers for "input.q" 
4. When broker1 receives a messages on "input.q", it gets load balanced between broker1 and broker4  as both has consumers looking for "input.q".
5. Whenever broker3 goes down, producer1 switches transparently to broker2, as its configured with failover.
6. I used prefetch size as 1, so that you can load balancing on consumers
Sample activemq configurations can be downloaded from here.


paulwong 2019-11-04 16:14 鍙戣〃璇勮
]]>
ACTIVE MQ HAhttp://www.aygfsteel.com/paulwong/archive/2019/11/01/434889.htmlpaulwongpaulwongFri, 01 Nov 2019 02:46:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/11/01/434889.htmlhttp://www.aygfsteel.com/paulwong/comments/434889.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/11/01/434889.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/434889.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/434889.html
ACTIVEMQ 鍙湁MASTER-SLAVE妯″紡錛岄泦緹や腑鐨勫涓妭鐐瑰叡浜秷鎭殑瀛樺偍錛屽涓妭鐐瑰悓鏃跺惎鍔ㄦ椂錛岀珵浜夋秷鎭瓨鍌ㄧ殑閿侊紝璋佸厛鍙栧緱錛岃皝灝辨槸MASTER錛屽綋MASTER DOWN鎺夋椂錛岄攣琚噴鏀撅紝SALVE涓┈涓婂張绔炰簤閿侊紝鍙栧緱鑰呮垚涓篗ASTER銆?br />
鏂規錛?br />
  • 瀹夎NFSV4
  • 淇敼娑堟伅瀛樺偍璺緞
    <persistenceAdapter>
      <kahaDB directory="/sharedFileSystem/sharedBrokerData"/>
    </persistenceAdapter>
  • 瀹㈡埛绔慨鏀硅繛鎺ュ瓧絎︿覆
    failover://(tcp://master:61616,tcp://slave:61616)?randomize=false
--銆?img src="https://activemq.apache.org/assets/img/MasterFailed.png" alt="" />


https://my.oschina.net/hzchenyh/blog/716424

https://www.iteye.com/blog/shift-alt-ctrl-2069250

https://stackoverflow.com/questions/53542928/activemq-ha-on-failover

https://activemq.apache.org/shared-file-system-master-slave

ActiveMQ(6)-鍩轟簬networkConnector鐨凚roker-Cluster鏂規
https://blog.csdn.net/jinjin603/article/details/78657387


Multi Data Centre Message Brokers with ActiveMQ
https://medium.com/thg-tech-blog/multi-data-centre-message-brokers-with-activemq-28495046370e

ActiveMQ涓殑NetworkConnector錛堢綉緇滆繛鎺ュ櫒錛夎瑙?br />https://www.iteye.com/blog/manzhizhen-2116920

a

paulwong 2019-11-01 10:46 鍙戣〃璇勮
]]>
ACTIVEMQ璁劇疆棰勫彇娑堟伅鏁扮洰http://www.aygfsteel.com/paulwong/archive/2019/10/31/434888.htmlpaulwongpaulwongThu, 31 Oct 2019 03:28:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/10/31/434888.htmlhttp://www.aygfsteel.com/paulwong/comments/434888.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/10/31/434888.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/434888.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/434888.html

https://stackoverflow.com/questions/35928089/activemq-how-to-prevent-message-from-going-to-dispatched-queue


璁劇疆鏂規硶錛屽湪CONNECT STRING涓緗細
tcp://localhost:61616?jms.prefetchPolicy.all=0 

tcp://localhost:61616?jms.prefetchPolicy.queuePrefetch=0 

queue = new ActiveMQQueue("TEST.QUEUE?consumer.prefetchSize=10"); 
consumer = session.createConsumer(queue);

http://activemq.apache.org/what-is-the-prefetch-limit-for.html

paulwong 2019-10-31 11:28 鍙戣〃璇勮
]]>
Springboot ActiveMQ jmsTemplate閰嶇疆http://www.aygfsteel.com/paulwong/archive/2019/07/24/434287.htmlpaulwongpaulwongWed, 24 Jul 2019 03:40:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/07/24/434287.htmlhttp://www.aygfsteel.com/paulwong/comments/434287.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/07/24/434287.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/434287.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/434287.html@Configuration
@DependsOn(value="cachingConnectionFactory")
public class JmsTemplateConfiguration {

@Value("${wechat.sendmessage.queue}")
private String queueName;

@Value("${wechat.sendmessage.topic}")
private String topicName;

@Value("${spring.jms.pub-sub-domain}")
private boolean isPubSubDomain;


/**
 * 瀹氫箟鐐瑰鐐歸槦鍒?br /> * 
@return
 
*/
@Bean
public Queue queue() {
    return new ActiveMQQueue(queueName);
}



/**
 * 瀹氫箟涓涓富棰?br /> * 
@return
 
*/
@Bean
public Topic topic() {
    return new ActiveMQTopic(topicName);
}

private final ObjectProvider<DestinationResolver> destinationResolver;
private final ObjectProvider<MessageConverter> messageConverter;
private final CachingConnectionFactory cachingConnectionFactory;

@Autowired
public JmsTemplateConfiguration(ObjectProvider<DestinationResolver> destinationResolver,
                                ObjectProvider<MessageConverter> messageConverter,
                                CachingConnectionFactory cachingConnectionFactory) {
    this.destinationResolver = destinationResolver;
    this.messageConverter = messageConverter;
    this.cachingConnectionFactory = cachingConnectionFactory;
}

/**
 * 閰嶇疆闃熷垪鐢熶駭鑰呯殑JmsTemplate
 * 
@return JmsTemplate
 
*/
@Bean(name="jmsQueueTemplate")
public JmsTemplate jmsQueueTemplate() {
    //璁劇疆鍒涘緩榪炴帴鐨勫伐鍘?br />    //JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    
//浼樺寲榪炴帴宸ュ巶錛岃繖閲屽簲鐢ㄧ紦瀛樻睜 榪炴帴宸ュ巶灝卞嵆鍙?/span>
    JmsTemplate jmsTemplate = new JmsTemplate(cachingConnectionFactory);
    //璁劇疆榛樿娑堣垂topic
   
//jmsTemplate.setDefaultDestination(topic());
    
//璁劇疆P2P闃熷垪娑堟伅綾誨瀷
    jmsTemplate.setPubSubDomain(isPubSubDomain);

    DestinationResolver destinationResolver = (DestinationResolver) this.destinationResolver.getIfUnique();
    if (destinationResolver != null) {
        jmsTemplate.setDestinationResolver(destinationResolver);
    }
    MessageConverter messageConverter = (MessageConverter) this.messageConverter.getIfUnique();
    if (messageConverter != null) {
        jmsTemplate.setMessageConverter(messageConverter);
    }
    //deliveryMode, priority, timeToLive 鐨勫紑鍏籌紝瑕佺敓鏁堬紝蹇呴』閰嶇疆涓簍rue錛岄粯璁alse
    jmsTemplate.setExplicitQosEnabled(true);
    //DeliveryMode.NON_PERSISTENT=1:闈炴寔涔?nbsp;; DeliveryMode.PERSISTENT=2:鎸佷箙
    
//瀹氫箟鎸佷箙鍖栧悗鑺傜偣鎸傛帀浠ュ悗錛岄噸鍚彲浠ョ戶緇秷璐?
    jmsTemplate.setDeliveryMode(DeliveryMode.PERSISTENT);
    //榛樿涓嶅紑鍚簨鍔?/span>
    System.out.println("榛樿鏄惁寮鍚簨鍔★細"+jmsTemplate.isSessionTransacted());
    //濡傛灉涓嶅惎鐢ㄤ簨鍔★紝鍒欎細瀵艱嚧XA浜嬪姟澶辨晥錛?br />    //浣滀負鐢熶駭鑰呭鏋滈渶瑕佹敮鎸佷簨鍔★紝鍒欓渶瑕侀厤緗甋essionTransacted涓簍rue
  
//jmsTemplate.setSessionTransacted(true);
    
//娑堟伅鐨勫簲絳旀柟寮忥紝闇瑕佹墜鍔ㄧ‘璁わ紝姝ゆ椂SessionTransacted蹇呴』琚緗負false錛屼笖涓篠ession.CLIENT_ACKNOWLEDGE妯″紡
    
//Session.AUTO_ACKNOWLEDGE  娑堟伅鑷姩絳炬敹
    
//Session.CLIENT_ACKNOWLEDGE  瀹㈡埛绔皟鐢╝cknowledge鏂規硶鎵嬪姩絳炬敹
    
//Session.DUPS_OK_ACKNOWLEDGE 涓嶅繀蹇呴』絳炬敹錛屾秷鎭彲鑳戒細閲嶅鍙戦?/span>
    jmsTemplate.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
    return jmsTemplate;
}

/**
 * 閰嶇疆鍙戝竷璁㈤槄鐢熶駭鑰呯殑JmsTemplate
 * 
@return JmsTemplate
 
*/
@Bean(name="jmsTopicTemplate")
public JmsTemplate jmsTopicTemplate() {
    //璁劇疆鍒涘緩榪炴帴鐨勫伐鍘?br />   //JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    
//浼樺寲榪炴帴宸ュ巶錛岃繖閲屽簲鐢ㄧ紦瀛樻睜 榪炴帴宸ュ巶灝卞嵆鍙?/span>
    JmsTemplate jmsTemplate = new JmsTemplate(cachingConnectionFactory);
    //璁劇疆榛樿娑堣垂topic
  
//jmsTemplate.setDefaultDestination(topic());
    
//璁劇疆鍙戝竷璁㈤槄娑堟伅綾誨瀷
    jmsTemplate.setPubSubDomain(isPubSubDomain);


    //deliveryMode, priority, timeToLive 鐨勫紑鍏籌紝瑕佺敓鏁堬紝蹇呴』閰嶇疆涓簍rue錛岄粯璁alse
    jmsTemplate.setExplicitQosEnabled(true);
    //DeliveryMode.NON_PERSISTENT=1:闈炴寔涔?nbsp;; DeliveryMode.PERSISTENT=2:鎸佷箙
    jmsTemplate.setDeliveryMode(DeliveryMode.PERSISTENT);

    //榛樿涓嶅紑鍚簨鍔?/span>
    System.out.println("鏄惁寮鍚簨鍔?+jmsTemplate.isSessionTransacted());
    //濡傛灉session甯︽湁浜嬪姟錛屽茍涓斾簨鍔℃垚鍔熸彁浜わ紝鍒欐秷鎭鑷姩絳炬敹銆傚鏋滀簨鍔″洖婊氾紝鍒欐秷鎭細琚啀嬈′紶閫併?br />    //jmsTemplate.setSessionTransacted(true);

    
//涓嶅甫浜嬪姟鐨剆ession鐨勭鏀舵柟寮忥紝鍙栧喅浜巗ession鐨勯厤緗?br />    //榛樿娑堟伅紜鏂瑰紡涓?錛屽嵆AUTO_ACKNOWLEDGE
    System.out.println("鏄惁娑堟伅紜鏂瑰紡"+jmsTemplate.getSessionAcknowledgeMode());

    //娑堟伅鐨勫簲絳旀柟寮忥紝闇瑕佹墜鍔ㄧ‘璁わ紝姝ゆ椂SessionTransacted蹇呴』琚緗負false錛屼笖涓篠ession.CLIENT_ACKNOWLEDGE妯″紡
    
//Session.AUTO_ACKNOWLEDGE  娑堟伅鑷姩絳炬敹
    
//Session.CLIENT_ACKNOWLEDGE  瀹㈡埛绔皟鐢╝cknowledge鏂規硶鎵嬪姩絳炬敹
    
//Session.DUPS_OK_ACKNOWLEDGE 涓嶅繀蹇呴』絳炬敹錛屾秷鎭彲鑳戒細閲嶅鍙戦?/span>
    jmsTemplate.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);

    return jmsTemplate;
}

}

paulwong 2019-07-24 11:40 鍙戣〃璇勮
]]>
Build Messaging Between Ruby/Rails Applications with ActiveMQhttp://www.aygfsteel.com/paulwong/archive/2019/07/12/434156.htmlpaulwongpaulwongFri, 12 Jul 2019 09:12:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/07/12/434156.htmlhttp://www.aygfsteel.com/paulwong/comments/434156.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/07/12/434156.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/434156.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/434156.htmlhttps://dev.to/kirillshevch/build-messaging-between-ruby-rails-applications-with-activemq-4fin

paulwong 2019-07-12 17:12 鍙戣〃璇勮
]]>
RABBITMQ璧勬簮http://www.aygfsteel.com/paulwong/archive/2019/06/28/434001.htmlpaulwongpaulwongFri, 28 Jun 2019 02:24:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/06/28/434001.htmlhttp://www.aygfsteel.com/paulwong/comments/434001.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/06/28/434001.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/434001.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/434001.htmlhttps://www.jianshu.com/p/79ca08116d57

Spring Boot 涓嬌鐢?RabbitMQ
https://juejin.im/post/59f194e06fb9a0451329ec53






paulwong 2019-06-28 10:24 鍙戣〃璇勮
]]>
How to implement JMS ReplyTo using SpringBoothttp://www.aygfsteel.com/paulwong/archive/2019/06/27/433981.htmlpaulwongpaulwongThu, 27 Jun 2019 01:20:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/06/27/433981.htmlhttp://www.aygfsteel.com/paulwong/comments/433981.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/06/27/433981.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/433981.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/433981.html

Request-Response is a message-exchange-pattern. In some cases, a message producer may want the consumers to reply to a message. The JMSReplyTo header indicates which destination, if any, a JMS consumer should reply to. The JMSReplyTo header is set explicitly by the JMS client; its contents will be a javax.jms.Destination object (either Topic or Queue).

In some cases, the JMS client will want the message consumers to reply to a temporary topic or queue set up by the JMS client. When a JMS message consumer receives a message that includes a JMSReplyTo destination, it can reply using that destination. A JMS consumer is not required to send a reply, but in some JMS applications, clients are programmed to do so.

For simplicity, this pattern is typically implemented in a purely synchronous fashion, as in web service calls over HTTP, which holds a connection open and waits until the response is delivered or the timeout period expires. However, request–response may also be implemented asynchronously, with a response being returned at some unknown later time.

For more information, check here.

Now, let’s jump into the code. In Spring, there are 2 ways to implement this (at least I know of).

  1. Using JMSTemplate
  2. Using Spring Integration

For demo purpose, I used ActiveMQ. However, you can implement this in other messaging systems like IBM MQ, Rabbit MQ, Tibco EMS, etc. In this demo, I send an ObjectMessage of type Order and reply with a Shipment object.

Using JMSTemplate

  1. First, we include the required dependencies. Replace the activemq dependency with your messaging system’s jars if not using ActiveMQ

     <dependencies>
         
    <dependency>
             
    <groupId>org.springframework.boot</groupId>
             
    <artifactId>spring-boot-starter-activemq</artifactId>
         
    </dependency>
         
    <dependency>
             
    <groupId>org.apache.activemq.tooling</groupId>
             
    <artifactId>activemq-junit</artifactId>
             
    <version>${activemq.version}</version>
             
    <scope>test</scope>
         
    </dependency>
         
    <dependency>
             
    <groupId>org.springframework.boot</groupId>
             
    <artifactId>spring-boot-starter-test</artifactId>
             
    <scope>test</scope>
         
    </dependency>
     
    </dependencies>
  2. Using the default spring.activemq. properties to configure the application with the ActiveMQ. However, you can do this inside a @Configuration class as well.

     spring:
       activemq:
         broker-url: tcp://localhost:
    61616
         non-blocking-redelivery: true
         packages:
           trust-all: true    
  3. Note in the above configuration spring.activemq.packages.trust-all can be changed to spring.activemq.packages.trusted with the appropriate packages.
  4. Now spring will do it’s magic and inject all the required Beans as usual :) However, in our code, we need to EnableJms

    import org.springframework.context.annotation.Configuration;
     
    import org.springframework.jms.annotation.EnableJms;

     @EnableJms
     @Configuration
     
    public class ActiveMQConfig {

         
    public static final String ORDER_QUEUE = "order-queue";
         
    public static final String ORDER_REPLY_2_QUEUE = "order-reply-2-queue";

     }
  5. First, we will configure the Producer

     @Slf4j
     @Service
     
    public class Producer {

         @Autowired
         JmsMessagingTemplate jmsMessagingTemplate;

         @Autowired
         JmsTemplate jmsTemplate;
          private Session session;

          @PostConstruct
           public void init(){
             jmsTemplate.setReceiveTimeout(1000L);
             jmsMessagingTemplate.setJmsTemplate(jmsTemplate);

             session = jmsMessagingTemplate.getConnectionFactory().createConnection()
                     .createSession(false, Session.AUTO_ACKNOWLEDGE);
           }

         
    public Shipment sendWithReply(Order order) throws JMSException {


             ObjectMessage objectMessage 
    = session.createObjectMessage(order);

             objectMessage.setJMSCorrelationID(UUID.randomUUID().toString());
             objectMessage.setJMSReplyTo(
    new ActiveMQQueue(ORDER_REPLY_2_QUEUE));
             objectMessage.setJMSCorrelationID(UUID.randomUUID().toString());
             objectMessage.setJMSExpiration(
    1000L);
             objectMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);

             
    return jmsMessagingTemplate.convertSendAndReceive(new ActiveMQQueue(ORDER_QUEUE),
                     objectMessage, Shipment.
    class); //this operation seems to be blocking + sync
         }
     }
  6. Note in the above code that, JmsMessagingTemplate is used instead of JmsTemplatebecause, we are interested in the method convertSendAndReceive. As seen in the method signature, it waits to receive the Shipment object from the consumer.
  7. Next, we can see the Receiver

     @Component
     
    public class Receiver implements SessionAwareMessageListener<Message> {

         @Override
         @JmsListener(destination 
    = ORDER_QUEUE)
         
    public void onMessage(Message message, Session session) throws JMSException {
             Order order 
    = (Order) ((ActiveMQObjectMessage) message).getObject();
             Shipment shipment 
    = new Shipment(order.getId(), UUID.randomUUID().toString());

             
    // done handling the request, now create a response message
             final ObjectMessage responseMessage = new ActiveMQObjectMessage();
             responseMessage.setJMSCorrelationID(message.getJMSCorrelationID());
             responseMessage.setObject(shipment);

             
    // Message sent back to the replyTo address of the income message.
             final MessageProducer producer = session.createProducer(message.getJMSReplyTo());
             producer.send(responseMessage);
         }
     }
  8. Using the javax.jms.Session the javax.jms.MessageProducer is created and used to send the reply message to the JMSReplyTo queue. In real life, this receiver could be a different application altogether.

Using Spring Integration

  1. First, we include the required dependencies in addition to the above dependencies

     <dependency>
       
    <groupId>org.springframework.integration</groupId>
       
    <artifactId>spring-integration-jms</artifactId>
     
    </dependency>
  2. Using the default spring.activemq. properties to configure the application with the ActiveMQ. However, you can do this inside a @Configuration class as well.

     spring:
       activemq
    :
         broker
    -url: tcp://localhost:61616
         non
    -blocking-redelivery: true
         packages
    :
           trust
    -all: true   
  3. Note in the above configuration spring.activemq.packages.trust-all can be changed to spring.activemq.packages.trusted with the appropriate packages.
  4. Next we create the required Beans for the Spring Integration.

     @EnableIntegration
     @IntegrationComponentScan
     @Configuration
     
    public class ActiveMQConfig {

         
    public static final String ORDER_QUEUE = "order-queue";
         
    public static final String ORDER_REPLY_2_QUEUE = "order-reply-2-queue";

         @Bean
         
    public MessageConverter messageConverter() {
             MappingJackson2MessageConverter converter 
    = new MappingJackson2MessageConverter();
             converter.setTargetType(MessageType.TEXT);
             converter.setTypeIdPropertyName(
    "_type");
             
    return converter;
         }

         @Bean
         
    public MessageChannel requests() {
             
    return new DirectChannel();
         }

         @Bean
         @ServiceActivator(inputChannel 
    = "requests")
         
    public JmsOutboundGateway jmsGateway(ActiveMQConnectionFactory activeMQConnectionFactory) {
             JmsOutboundGateway gateway 
    = new JmsOutboundGateway();
             gateway.setConnectionFactory(activeMQConnectionFactory);
             gateway.setRequestDestinationName(ORDER_QUEUE);
             gateway.setReplyDestinationName(ORDER_REPLY_2_QUEUE);
             gateway.setCorrelationKey(
    "JMSCorrelationID");
             gateway.setSendTimeout(
    100L);
             gateway.setReceiveTimeout(
    100L);
             
    return gateway;
         }

         @Autowired
         Receiver receiver;

         @Bean
         
    public DefaultMessageListenerContainer responder(ActiveMQConnectionFactory activeMQConnectionFactory) {
             DefaultMessageListenerContainer container 
    = new DefaultMessageListenerContainer();
             container.setConnectionFactory(activeMQConnectionFactory);
             container.setDestinationName(ORDER_QUEUE);
             MessageListenerAdapter adapter 
    = new MessageListenerAdapter(new Object() {

                 @SuppressWarnings(
    "unused")
                 
    public Shipment handleMessage(Order order) {
                     
    return receiver.receiveMessage(order);
                 }

             });
             container.setMessageListener(adapter);
             
    return container;
         }
     }
  5. Next, we will configure the MessagingGateway

     @MessagingGateway(defaultRequestChannel = "requests")
     
    public interface ClientGateway {
         Shipment sendAndReceive(Order order);
     }
  6. We then Autowire this gateway in our Component class when we want to send and receive the message. A sample is shown below.

     @Slf4j
     @Component
     
    public class Receiver {
         
    public Shipment receiveMessage(@Payload Order order) {
             Shipment shipment 
    = new Shipment(order.getId(), UUID.randomUUID().toString());
             
    return shipment;
         }
     }
  7. Next we configure the Componen to process the Order message. After successful execution, this component will send the Shipment message to the JMSReplyTo queue. In real life, this receiver could be a different application altogether.

For those, who just want to clone the code, head out to aniruthmp/jms



paulwong 2019-06-27 09:20 鍙戣〃璇勮
]]>
ACTIVE MQ楂樼駭鐗規?/title><link>http://www.aygfsteel.com/paulwong/archive/2019/06/26/433972.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 26 Jun 2019 06:13:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2019/06/26/433972.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/433972.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2019/06/26/433972.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/433972.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/433972.html</trackback:ping><description><![CDATA[<a target="_blank">https://blog.51cto.com/1754966750/category17.html</a><br /><img src ="http://www.aygfsteel.com/paulwong/aggbug/433972.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2019-06-26 14:13 <a href="http://www.aygfsteel.com/paulwong/archive/2019/06/26/433972.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>JMS娑堟伅娑堣垂鐨勯『搴忔?/title><link>http://www.aygfsteel.com/paulwong/archive/2019/06/24/433942.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Mon, 24 Jun 2019 09:42:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2019/06/24/433942.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/433942.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2019/06/24/433942.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/433942.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/433942.html</trackback:ping><description><![CDATA[鐜版湁鐨勭郴緇熸灦鏋勯兘鏄垎甯冨紡鐨勩傛湁澶氫釜娑堟伅鐨勫彂閫佽呭拰澶氫釜娑堟伅鐨勬秷璐硅呫備緥濡傝鍗曞垱寤烘秷鎭拰璁㈠崟鏀粯娑堟伅錛屾垜浠渶瑕佷繚璇佸厛娑堣垂璁㈠崟鍒涘緩娑堟伅錛岀劧鍚庢秷璐硅鍗曟敮浠樻秷鎭?br /><br />濡備綍瑙e喅MQ娑堟伅娑堣垂欏哄簭闂<br /><a target="_blank">https://segmentfault.com/a/1190000014512075</a><br /><br />jms-濡備綍淇濊瘉娑堟伅鐨勯『搴?br /><a target="_blank">https://leokongwq.github.io/2017/01/23/jms-message-order.html</a><br /><br /><br /><br /><br /><br /><br /><br /><img src ="http://www.aygfsteel.com/paulwong/aggbug/433942.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2019-06-24 17:42 <a href="http://www.aygfsteel.com/paulwong/archive/2019/06/24/433942.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>JMS鏈綆鍗曠殑瑙i噴http://www.aygfsteel.com/paulwong/archive/2012/06/06/380104.htmlpaulwongpaulwongWed, 06 Jun 2012 02:18:00 GMThttp://www.aygfsteel.com/paulwong/archive/2012/06/06/380104.htmlhttp://www.aygfsteel.com/paulwong/comments/380104.htmlhttp://www.aygfsteel.com/paulwong/archive/2012/06/06/380104.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/380104.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/380104.html

paulwong 2012-06-06 10:18 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 西安市| 江安县| 河曲县| 林甸县| 米易县| 江达县| 治多县| 汽车| 西吉县| 峨眉山市| 新干县| 柳州市| 巴南区| 怀远县| 珠海市| 油尖旺区| 澜沧| 乌兰察布市| 永定县| 定日县| 景泰县| 温宿县| 综艺| 贺兰县| 南川市| 建湖县| 舒城县| 湘潭县| 金湖县| 文昌市| 宜章县| 鄂温| 全州县| 固原市| 福鼎市| 登封市| 潜江市| 玛纳斯县| 建宁县| 华宁县| 九龙城区|