Nats-streaming basic set up

830 views
Skip to first unread message

Suma B N

unread,
Jul 5, 2018, 5:19:57 AM7/5/18
to nats
Hi,

I'm new to NATS. I'm trying to run one basic pub sub using Nats-streaming. I used the example given in nats github.


Publisher is publishing the message and I can see the connection created in debug logs of nats server and also channel got created for the subject "foo". 

But I cant see any message delivered to Subscriber.

Can anyone please help me solving this?

Thanks in advance.
-Suma

Stevo Slavić

unread,
Jul 5, 2018, 5:33:37 AM7/5/18
to nat...@googlegroups.com
Hello Suma,

I think it's a bug in the example. Try to change the order, register subscriber before message is published.
If I'm not mistaken, by default subscriber will receive only messages which were published after subscription has been created.
That's why there's the next example which explains how to change the defaults for subscription and to control/request replay/delivery of messages which were published even before subscription was created https://github.com/nats-io/go-nats-streaming#subscription-start-ie-replay-options

Kind regards,
Stevo Slavic.

--
You received this message because you are subscribed to the Google Groups "nats" group.
To unsubscribe from this group and stop receiving emails from it, send an email to natsio+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Suma B N

unread,
Jul 5, 2018, 6:14:01 AM7/5/18
to nats
Hi,

I dont think there is an issue in the order of publisher and subscriber. Because I even tried putting publisher code and subscriber code in different files and subscriber is continuously listening and not getting any subscribed information. 

Thanks,
Suma

iv...@synadia.com

unread,
Jul 5, 2018, 10:17:53 AM7/5/18
to nats
To make sure, you are running the NATS Streaming Server (nats-streaming-server), right? 
Also, the subscriber needs to be a Streaming subscriber, not NATS subscriber. 

For instance:
```

[97361] 2018/07/05 08:15:14.606332 [INF] STREAM: Starting nats-streaming-server[test-cluster] version 0.10.2

[97361] 2018/07/05 08:15:14.606407 [INF] STREAM: ServerID: 5XC0QVzYXeyvh5AMmZ0pLg

[97361] 2018/07/05 08:15:14.606410 [INF] STREAM: Go version: go1.10.3

[97361] 2018/07/05 08:15:14.607455 [INF] Starting nats-server version 1.1.0

[97361] 2018/07/05 08:15:14.607464 [INF] Git commit [not set]

[97361] 2018/07/05 08:15:14.607656 [INF] Listening for client connections on 0.0.0.0:4222

[97361] 2018/07/05 08:15:14.607662 [INF] Server is ready

[97361] 2018/07/05 08:15:14.638756 [INF] STREAM: Recovering the state...

[97361] 2018/07/05 08:15:14.638777 [INF] STREAM: No recovered state

[97361] 2018/07/05 08:15:14.890471 [INF] STREAM: Message store is MEMORY

[97361] 2018/07/05 08:15:14.890523 [INF] STREAM: ---------- Store Limits ----------

[97361] 2018/07/05 08:15:14.890528 [INF] STREAM: Channels:                  100 *

[97361] 2018/07/05 08:15:14.890531 [INF] STREAM: --------- Channels Limits --------

[97361] 2018/07/05 08:15:14.890533 [INF] STREAM:   Subscriptions:          1000 *

[97361] 2018/07/05 08:15:14.890536 [INF] STREAM:   Messages     :       1000000 *

[97361] 2018/07/05 08:15:14.890539 [INF] STREAM:   Bytes        :     976.56 MB *

[97361] 2018/07/05 08:15:14.890542 [INF] STREAM:   Age          :     unlimited *

[97361] 2018/07/05 08:15:14.890544 [INF] STREAM:   Inactivity   :     unlimited *

[97361] 2018/07/05 08:15:14.890547 [INF] STREAM: ----------------------------------

```


Then publish a message:

```

IvanMBP:go-nats-streaming ivan$ go run examples/stan-pub/main.go foo msg1

Published [foo] : 'msg1'

```


You see the channel being created

```

[97361] 2018/07/05 08:15:26.507766 [INF] STREAM: Channel "foo" has been created

```


You can even start the subscriber after the fact. Here, we ask the subscriber to receive all messages in the channel:


```

Connected to nats://localhost:4222 clusterID: [test-cluster] clientID: [me]

subscribing with DeliverAllAvailable

Listening on [foo], clientID=[me], qgroup=[] durable=[]

[#1] Received on [foo]: 'sequence:1 subject:"foo" data:"msg1" timestamp:1530800142653817095 '

```


Let me know if that helps.

Ivan.

Suma B N

unread,
Jul 6, 2018, 5:10:33 AM7/6/18
to nat...@googlegroups.com
Thank you. Yes Issue got resolved. that was due to some network issue. 

Is there anywhere documentation on stan config file available? 

I got this one.

# NATS specific configuration
port: 4222
cluster {
  listen: 0.0.0.0:6222
  routes: ["nats://host2:6222", "nats://host3:6222"]
}

# NATS Streaming specific configuration
streaming {
  id: mycluster
  store: file
  dir: store
  cluster {
    node_id: "a"
    peers: ["b", "c"]
  }
}

Regards,
Suma B N

iv...@synadia.com

unread,
Jul 6, 2018, 11:18:41 AM7/6/18
to nats
Suma,

Documentation of the config file is available here. I would also recommend that you read the whole README since you are new to NATS Streaming.
It's rather small compared to other products, but it should give you the bases.

Ivan.
Reply all
Reply to author
Forward
0 new messages