GithubHelp home page GithubHelp logo

libertyarow / nats-streaming-spring Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wanlinus/nats-streaming-spring

0.0 0.0 0.0 18 KB

Nats Streaming Spring

Home Page: https://wanlinus.github.io/2018/10/13/%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E4%BB%B6%E4%B9%8BNats/

License: MIT License

Java 100.00%

nats-streaming-spring's Introduction

Nats Streaming Spring

NSS -- 一个集成NATS-Streaming到Spring boot的插件

Table of Contents

Description

Nats 一个使用Golang写的高性能MQ中间件,但是缺乏对Spring的支持. 在工作中Spring已经成为Java开发企业级标准. 所以社区急需一个能集成Spring的插件, 所以nss就诞生了. 这个插件使用NATS-Streaming. 因为NATS不支持数据持久化

Geting Start

https://github.com/wanlinus/nats-streaming-spring.git
cd nats-streaming-spring
mvn clean install

maven:

<dependency>
	<groupId>cn.wanlinus</groupId>
    <artifactId>nats-streaming-spring</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>

开启支持NatsStreaming

@EnableNatsStreaming
@SpringBootApplication
public class NSSApplication {
    public static void main(String[] args) {
        SpringApplication.run(NSSApplication.class, args);
    }
}

在application.yaml中配置nats-streaming

spring:
  nats:
    streaming:
      cluster-id: test-cluster
      nats-urls: nats://10.0.0.20:4223

消费消息

@Service
public class NatsService {
    private static final Logger logger = LoggerFactory.getLogger(NatsService.class);

    @Subscribe(value = "bbb", durableName = "asd")
    public void asd(Message message) {
        logger.info("收到bbb msg[{}]", new String(message.getData(), StandardCharsets.UTF_8));
    }
}

生产消息

    @Override
    public void run(String... args) throws Exception {
        new Thread(() -> {
            try {
                for (int i = 0; i < 10;i++) {
                    logger.info("发送消息");
                    String msg = "send msg " + i;
                    connection.publish("bbb", msg.getBytes(StandardCharsets.UTF_8));
                    Thread.sleep(1000);
                }

            } catch (IOException | InterruptedException | TimeoutException e) {
                e.printStackTrace();
            }
        }).start();
    }

然后就可以快乐的使用啦

About Repo

spring集成Nats

nats-spring测试代码

Maintainers

@ wanli

Contributing

非常欢迎你的加入! 提一个Issue 或者提交一个 Pull Request.

Havefun 遵循 Contributor Covenant 行为规范.

Contributors

感谢以下参与项目的人:

img

License

MIT © Wanli

nats-streaming-spring's People

Contributors

wanlinus avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.