当前位置: 首页 > news >正文

网站备案报价厦门人才网手机版

网站备案报价,厦门人才网手机版,工业设计优秀作品,制作旅游网站原始状态的 activemq-client sdk 集成非常方便&#xff0c;也更适合定制。就是有些同学&#xff0c;可能对原始接口会比较陌生&#xff0c;会希望有个具体的示例。 <dependency><groupId>org.apache.activemq</groupId><artifactId>activemq-client&l…

原始状态的 activemq-client sdk 集成非常方便,也更适合定制。就是有些同学,可能对原始接口会比较陌生,会希望有个具体的示例。

<dependency><groupId>org.apache.activemq</groupId><artifactId>activemq-client</artifactId><version>${activemq.version}</version>
</dependency><dependency><groupId>org.apache.activemq</groupId><artifactId>activemq-pool</artifactId><version>${activemq.version}</version>
</dependency>

希望更加简化使用的同学,可以使用:

activemq-solon-cloud-plugin (使用更简单,定制性弱些)

1、添加集成配置

先使用 Solon 初始器 先生成一个 Solon Web 模板项目,然后添加上面的 activemq-client 依赖。再做个配置约定(也可按需定义):

  • “solon.activemq”,作为配置前缀
    • “properties”,作为公共配置
    • “producer”,作为生态者专属配置(估计用不到)
    • “consumer”,作为消费者专属配置(估计用不到)

具体的配置属性,参考自:ActiveMQConnectionFactory

solon.app:name: "demo-app"group: "demo"# 配置可以自由定义,与 @Bean 代码对应起来即可(以下为参考)
solon.activemq:properties:  #公共配置(配置项,参考:ActiveMQConnectionFactory)brokerURL: "failover:tcp://localhost:61616"redeliveryPolicy:initialRedeliveryDelay: 5000backOffMultiplier: 2useExponentialBackOff: truemaximumRedeliveries: -1maximumRedeliveryDelay: 3600_000

添加 java 配置器

@Configuration
public class ActivemqConfig {@Bean(destroyMethod = "stop")public Connection client(@Inject("${solon.activemq.properties}") Props common) throws Exception {String brokerURL = (String) common.remove("brokerURL");String userName = (String) common.remove("userName");String password = (String) common.remove("password");ActiveMQConnectionFactory factory;if (Utils.isEmpty(userName)) {factory = new ActiveMQConnectionFactory(brokerURL);} else {factory = new ActiveMQConnectionFactory(brokerURL, userName, password);}//绑定额外的配置并创建连接Connection connection = common.bindTo(factory).createConnection();connection.start();return connection;}@Beanpublic IProducer producer(Connection connection) throws Exception {return new IProducer(connection);}@Beanpublic void consumer(Connection connection,MessageListener messageListener) throws Exception {Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);Destination destination = session.createTopic("topic.test");MessageConsumer consumer = session.createConsumer(destination);consumer.setMessageListener(messageListener);}
}

activemq 的消息发送的代码比较复杂,所以我们可以做个包装处理(用于上面的配置构建),临时命名为 IProducer:

public class IProducer {private Connection connection;public IProducer(Connection connection) {this.connection = connection;}public void send(String topic, MessageBuilder messageBuilder) throws JMSException {Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);Destination destination = session.createTopic(topic);MessageProducer producer = session.createProducer(destination);producer.send(destination, messageBuilder.build(session));}@FunctionalInterfacepublic static interface MessageBuilder {Message build(Session session) throws JMSException;}
}

3、代码应用

发送(或生产),这里代控制器由用户请求再发送消息(仅供参考):

@Controller
public class DemoController {@Injectprivate IProducer producer;@Mapping("/send")public void send(String msg) throws Exception {//发送producer.send("topic.test", s -> s.createTextMessage("test"));}
}

监听(或消费),这里采用订阅回调的方式:(仅供参考)

@Component
public class DemoMessageListener implements MessageListener {@Overridepublic void onMessage(Message message) {System.out.println(message);RunUtil.runAndTry(message::acknowledge);}
}
http://www.ritt.cn/news/8450.html

相关文章:

  • dreamweaver免费安装邯郸seo推广
  • 网站建设中的数据库规划seo交流论坛seo顾问
  • 网站图片优化怎么做在线识别图片
  • 浏览器被病毒网站绑了怎么做百度最新人工智能
  • 国家发改委重大建设项目网站东莞关键词seo
  • 计算机网站建设 是什么意思电商运营的基本流程
  • 做视频链接哪个网站没有广告seo快速排名是什么
  • 深圳有什么好的企业网站谷歌搜索引擎首页
  • 2022搜索引擎白银网站seo
  • 佛山网站优化建设app开发者需要更新此app
  • 腾讯企业邮箱登录入口手机版四川seo技术培训
  • 种子搜索神器在线引擎北京网站优化步骤
  • 网站推广的方式有app推广方式有哪些
  • 南京网站建设推广销售平台排名
  • 网站建设分几个阶段凡科网免费建站
  • 旅游电子商务 网站建设网站怎么开发
  • 设计做任务的网站惠州seo报价
  • 响应式企业网站开发所用的平台百度免费seo
  • 企业模版桔子seo工具
  • 培训机构做网站宣传网络营销的有哪些特点
  • 网站设计 图片网站链接查询
  • 衡水做网站的地方友情链接获取的途径有哪些
  • 北京朝阳区地图高清版大图seo优化排名易下拉用法
  • 西安注册公司在哪个网站系统新网站百度收录要几天
  • 做任务有q币的网站网站建设方案模板
  • 网站平台开发公司自动点击器永久免费版
  • asp框架商城网站模板百度一下你就知道了
  • 临海做网站的公司刚刚中国宣布重大消息
  • wordpress升级主题网络优化的基本方法
  • 网站的建设是什么宁波seo公司排名榜