Skip to content

Latest commit

 

History

History
83 lines (67 loc) · 2.32 KB

File metadata and controls

83 lines (67 loc) · 2.32 KB

embedded-nats

Maven dependency

pom.xml
<dependency>
    <groupId>com.playtika.testcontainers</groupId>
    <artifactId>embedded-nats</artifactId>
    <scope>test</scope>
</dependency>

Consumes (via bootstrap.properties)

  • embedded.nats.enabled (true|false, default is true)

  • embedded.nats.reuseContainer (true|false, default is false)

  • embedded.nats.dockerImage (default is 'nats:2.15')

  • embedded.toxiproxy.proxies.nats.enabled Enables both creation of the container with ToxiProxy TCP proxy and a proxy to the embedded-nats container.

Produces

  • embedded.nats.host

  • embedded.nats.port

  • embedded.nats.httpMonitorPort

  • embedded.nats.routeConnectionsPort

  • embedded.nats.toxiproxy.host

  • embedded.nats.toxiproxy.port

  • embedded.nats.networkAlias

  • embedded.nats.internalClientPort

  • embedded.nats.internalHttpMonitorPort

  • embedded.nats.internalRouteConnectionsPort

  • Bean NatsContainer embeddedNats

  • Bean ToxiproxyClientProxy natsContainerProxy

Notes

Uses NatsContainer from io.github.amadeusitgroup.testcontainers:nats. Exposes ports 4222 (client), 6222 (routing), 8222 (HTTP monitoring). No security enabled by default; any credentials are accepted.

To enable JetStream or authentication, inject the NatsContainer bean and configure it before the context starts, or use the embedded.nats.command property to pass flags (e.g. --jetstream).

Create client with ToxiProxy

You can also create client pointed at ToxiProxy TCP proxy:

  1. Provide properties:

    src/test/resources/bootstrap.properties
    embedded.toxiproxy.proxies.nats.enabled=true
To manipulate ToxiProxy inject the following bean into your tests:
@Autowired
ToxiproxyClientProxy natsContainerProxy;

Create Nats client

@Bean(destroyMethod = "close")
public Connection natsConnection(@Value("${embedded.nats.host}") String host,
                                 @Value("${embedded.nats.port}") int port) {
    Options options = new Options.Builder()
            .server(String.format("nats://%s:%s", host, port))
            .build();
    return Nats.connect(options);
}