项目作者: dstrelec

项目描述 :
Provides Familiar Spring Abstractions for NATS messaging system
高级语言: Java
项目地址: git://github.com/dstrelec/nats.git
创建时间: 2017-02-03T23:28:37Z
项目社区:https://github.com/dstrelec/nats

开源协议:Apache License 2.0

下载


Spring NATS

License

This project provides support for using Spring and Java with NATS messaging system.

It provides a “template” as a high-level abstraction for sending messages.
It also provides support for Message-driven POJOs with @NatsListener annotations and a “listener container”.
These libraries promote the use of dependency injection and declarative.

The project was inspired by Spring Kafka and
Spring AMQP, so you will see a lots of similarities
to those Spring messaging projects.

Features

  • Spring Boot auto-configuration starter
  • Listener container for asynchronous processing of inbound messages
  • NatsTemplate for sending messages

Quick Start

The recommended way to get started using nats-starter in your project is with a dependency management
system – the snippet below can be copied and pasted into your build.

  1. <dependencies>
  2. <dependency>
  3. <groupId>dstrelec.nats</groupId>
  4. <artifactId>nats-starter</artifactId>
  5. <version>0.1.0</version>
  6. </dependency>
  7. </dependencies>

Checking out and Building

To check out the project and build from source, do the following:

  1. git clone git://github.com/dstrelec/nats.git
  2. cd nats
  3. maven install

The Java SE 7 or higher is recommended to build the project.

Basic Usage

  1. @EnableNats
  2. @Configuration
  3. public class AppConfig {
  4. @Bean
  5. public NatsConnectionFactory natsConnectionFactory() {
  6. return new DefaultConnectionFactory();
  7. }
  8. @Bean
  9. public NatsTemplate natsTemplate() {
  10. return new NatsTemplate(natsConnectionFactory());
  11. }
  12. @Bean
  13. public NatsListenerContainerFactory natsListenerContainerFactory() {
  14. DefaultNatsListenerContainerFactory factory = new DefaultNatsListenerContainerFactory();
  15. factory.setConnectionFactory(natsConnectionFactory());
  16. factory.setMessageConverter(new StringJsonMessageConverter());
  17. return factory;
  18. }
  19. }
  1. @Component
  2. public class MyComponent {
  3. @Autowired
  4. private NatsTemplate natsTemplate;
  5. public void sayHello() {
  6. natsTemplate.publish("foo", "\"Hello world.\"");
  7. }
  8. }
  1. @Component
  2. @NatsListener(subjects = "foo")
  3. public class MyListener {
  4. @NatsHandler
  5. public void receiveMessage(@Payload String greetings) {
  6. System.out.println(greetings);
  7. }
  8. }

Resources

For more information, please visit the Spring NATS website at:
Reference Manual

License

Nats Enabler is released under the terms of the Apache 2.0 license.