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

网站建设之开展电子商务seo顾问服

网站建设之开展电子商务,seo顾问服,教学网站开发源码,深圳有哪些软件开发公司目录 概述使用准备工作引入依赖创建Topic代码应用启动消息接收再扩展一个 结束 概述 github 文档地址 rocket mq example RocketMQ 版本为 5.1.4 使用 准备工作 阅读此文需要事先准备 RocketMQ ,如有疑问,请移步 RocketMQ 服务搭建 引入依赖 此处…

目录

  • 概述
  • 使用
    • 准备工作
    • 引入依赖
    • 创建Topic
    • 代码
    • 应用启动
    • 消息接收
    • 再扩展一个
  • 结束

概述

github 文档地址
rocket mq example

RocketMQ 版本为 5.1.4

使用

准备工作

阅读此文需要事先准备 RocketMQ ,如有疑问,请移步 RocketMQ 服务搭建

引入依赖

此处,多依赖了一些依赖。

<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
</dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>

创建Topic

sh bin/mqadmin updateTopic -n localhost:9876 -c DefaultCluster -t test-topic

在这里插入图片描述

代码

配置 Input 和 Output 的 Binding 信息并配合 @EnableBinding 注解使其生效

@EnableBinding({ Source.class, Sink.class })
@EnableDiscoveryClient
@SpringBootApplication
public class MqApplication {public static void main(String[] args) {SpringApplication.run(MqApplication.class);}
}

配置 Binding 信息:

# 配置rocketmq的nameserver地址
spring.cloud.stream.rocketmq.binder.name-server=10.xx.xx.143:9876
# 定义name为output的binding
spring.cloud.stream.bindings.output.destination=test-topic
spring.cloud.stream.bindings.output.content-type=application/json
# 定义name为input的binding
spring.cloud.stream.bindings.input.destination=test-topic
spring.cloud.stream.bindings.input.content-type=application/json
spring.cloud.stream.bindings.input.group=test-group

发送消息代码:

public class RocketMQProducer {public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {DefaultMQProducer producer = new DefaultMQProducer("producer_group");producer.setNamesrvAddr("10.xx.xx.143:9876");producer.start();Message msg = new Message("test-topic", "tagStr", "message from rocketmq producer".getBytes());producer.send(msg);}
}

应用启动

1.增加配置,在应用的 /src/main/resources/application.properties 中添加基本配置信息

spring:application:name: mq
server:port: 9700

2.启动应用,支持 IDE 直接启动和编译打包后启动。

  • IDE 直接启动:找到主类 RocketMQApplication,执行 main 方法启动应用。
  • 打包编译后启动:首先执行 mvn clean package 将工程编译打包,然后执行 java -jar rocketmq-example.jar 启动应用。

消息接收

使用 name 为 output 对应的 binding 发送消息到 test-topic 这个 topic。

@Service
public class ReceiveService {@StreamListener("input1")public void receiveInput1(String receiveMsg) {System.out.println("input1 receive: " + receiveMsg);}
}

在这里插入图片描述

再扩展一个

一个服务中要使用多个 Topic ,这种情况如何解决?下面给出解决方案。

public interface Input2Sink extends Sink {String INPUT2 = "input2";@Input(Input2Sink.INPUT2)SubscribableChannel input2();
}
public interface Output2Source extends Source {String OUTPUT2 = "output2";@Output(Output2Source.OUTPUT2)MessageChannel output2();
}
@Service
public class ReceiveService {@StreamListener("input")public void receiveInput1(String receiveMsg) {System.out.println("input receive: " + receiveMsg);}@StreamListener("input2")public void receiveInput2(String receiveMsg) {System.out.println("input2 receive: " + receiveMsg);}
}
@EnableBinding(value = {Source.class, Sink.class, Output2Source.class, Input2Sink.class})
@EnableDiscoveryClient
@SpringBootApplication
public class MqApplication {public static void main(String[] args) {SpringApplication.run(MqApplication.class);}
}

结果如下:
在这里插入图片描述

结束

spring cloud alibaba RocketMQ 最佳实践 ,至此就结束了,如有疑问,欢迎评论区留言。

http://www.wooajung.com/news/23792.html

相关文章:

  • 自己可以建网站吗郑州seo代理公司
  • 模板网站的优缺点seo上海推广公司
  • bootstrap网站开发实例教程安卓嗅探app视频真实地址
  • 西安有哪些网站建设外包公司百度搜索引擎的网址是多少
  • 盐城市建设银行网站市场营销专业就业方向
  • 设计制作小车二教案网络优化工程师前景如何
  • WordPress如何建小语种网站产品营销方案
  • 做网站联系电话今天最新新闻10条
  • 国外html5模板网站室内设计培训班学费一般多少
  • 购物网站怎么建设阿拉营销网站
  • 做动车哪个网站查郑州关键词排名顾问
  • 个人做网站开发色盲测试图看图技巧
  • 网站开发容易找工作吗百度快照seo
  • 手机怎么做动漫微电影网站成品网站1688入口网页版怎样
  • 做网站公众号全网优化推广
  • 页面模板只有注册的人可以弄吗seo网站课程
  • 良品铺子的网站建设目标自己可以做网站推广吗
  • 中山网站建设服务网络优化工程师招聘信息
  • 广州做网站的哪家好南宁seo渠道哪家好
  • 营销型公司网站免费网站推广网站短视频
  • 做全网营销型网站建设核心关键词
  • 怎样做网站流量统计seo修改器
  • 浙江省建设安全监督站的网站河北关键词seo排名
  • 网站关键词优化怎么做信息流广告优化
  • 在国内做电商网站需要什么审核网站seo查询
  • ae做动画教程网站怎么在网络上推广
  • 珠海房地产网站建设上海今天刚刚发生的新闻
  • 手机企业网站多少钱网站销售怎么推广
  • 热铁盒网页托管b2b网站推广优化
  • 怎么给网站做优化杭州排名优化公司电话