nats

Version, currently main branch1 version
  • main branchlatestJan 7, 2022

github.com/nats-io/nats.cr

Crystal client for NATS

47 stars
0 dependents
License: Apache-2.0

Installation

# Add this to your shard.yml
dependencies:
  nats:
    github: nats-io/nats.cr
    branch: main

main is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
>= 1.30, < 2.0
License
Apache-2.0
Author
Derek Collison <derek@nats.io>
Targets
  • nats-pub from bin/nats-pub.cr
  • nats-req from bin/nats-req.cr
  • nats-sub from bin/nats-sub.cr

Dependencies

This version declares no dependencies.

README

# NATS - Crystal Client

Simple NATS client for the [Crystal](https://crystal-lang.org) programming language.

[![License Apache 2](https://img.shields.io/badge/License-Apache2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![Build Status](https://travis-ci.org/nats-io/nats.cr.svg?branch=master)](http://travis-ci.org/nats-io/nats.cr)

## Installation

1. Add the dependency to your `shard.yml`:

```yaml
   dependencies:
     nats:
       github: nats-io/nats.cr
```

2. Run `shards install`

## Usage

```crystal
require "nats"

nc = NATS::Connection.new("demo.nats.io")
nc.subscribe("foo") { |msg| puts "Received '#{msg}'"}
nc.publish("foo", "Hello!")

sub = nc.subscribe("req") do |msg|
  msg.respond("ANSWER is 42")
end

answer = nc.request("req", "Help!")
puts "Received a response '#{answer}'!"

sub.close
nc.close
```

## License

Unless otherwise noted, the NATS source files are distributed under
the Apache Version 2.0 license found in the LICENSE file.