你有几个邮箱呢?你是怎么分配它们的用途呢?码云账号增加多邮箱支持!
Watch 2 Star 3 Fork 2

朽之丶 / spring-boot-starter-natsJava

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
Nothing here. spread retract

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

使用方式

1、获取代码

git clone https://github.com/ChinaSilence/spring-boot-starter-nats.git

2、安装到本地 Maven 仓库

mvn clean install

3、在项目中添加依赖

<!-- Nats 消息中间件 -->
<dependency>
    <groupId>com.anoyi</groupId>
    <artifactId>spring-boot-starter-nats</artifactId>
    <version>1.0-RELEASE</version>
</dependency>

4、配置 Nats 相关参数

# 默认 nats://127.0.0.1
spring:
  nats:
    urls:
      - nats://192.168.99.102:30000
      - nats://192.168.99.102:30001
      - nats://192.168.99.102:30002

5、发布订阅消息

@Autowired
private nats.client.Nats nats;

...

// 订阅消息
public void subscribe() {
	nats.subscribe("some.nats.subject", new MessageHandler() {
	@Override
		public void onMessage(Message message) {
			System.out.println("Received: " + message);
		}
	});
}

// 发布消息
public void send() {
	nats.subscribe("some.nats.subject", "message content");
}

Comments ( 0 )

You need to Sign in for post a comment

Help Search