Nats streaming architecture with Golang

474 views
Skip to first unread message

sachin walia

unread,
Mar 23, 2017, 5:17:51 PM3/23/17
to nats
Hi,

I am new to both Nats streaming as well as Golang so pardon if question sounds too basic. 

I wanted to understand how interaction of typical golang application with Nats looks like:

1. Is connection created on demand or we create a thread-safe reference and use it whenever we need to publish a message
2. For consumers will Nats push the message or it needs to be polled by consumers on a periodic basis?
3. How does re-connect works in case of failures / timeouts etc?

thanks.

Larry McQueary

unread,
Mar 24, 2017, 1:58:58 PM3/24/17
to nats
1. Is connection created on demand or we create a thread-safe reference and use it whenever we need to publish a message

Typically the latter -- you would create a NATS connection (which is inherently thread-safe) and re-use it  whenever required for sending messages and receiving messages on subscriptions you've set up/

2. For consumers will Nats push the message or it needs to be polled by consumers on a periodic basis?

The NATS server (gnatsd) pushes messages to the client's connection as they become available. Your client can process messages synchronously by invoking NextMsg() on the subscription and waiting for the next message to appear, or asynchronously by registering a MsgHandler for the Subscription which will be invoked automatically whenever a new message is received for that Subscription. 

The go-nats README is a great place to see some basic examples.

3. How does re-connect works in case of failures / timeouts etc?

See Clustered Usage in the go-nats README.


--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Larry McQueary | NATS.IO Product Management

sachin walia

unread,
Mar 29, 2017, 7:12:56 PM3/29/17
to nats
Larry,

thanks I figured out after posting this question. Being from JVM world things are little different in golang. But I found golang much more liberating than being dependent on way too many dependencies in JVM frameworks (Spring etc..)

I am creating Nats Connection (NatsConn stan.Conn) as a global resource during Application initialization. This same connection is used in setting up all the necessary subscribers with respective topics. I think I got it working well so far. 
I appreciate your response though and would post back if hit any roadblock.

Off topic -- Nats streaming doesn't seem to support queue/topic/message replication among multiple instances if I understand correctly. If not is this part of roadmap in near future?

thanks,
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.

Ivan Kozlovic

unread,
Mar 31, 2017, 8:01:58 PM3/31/17
to nats
Off topic -- Nats streaming doesn't seem to support queue/topic/message replication among multiple instances if I understand correctly. If not is this part of roadmap in near future?

Correct. Clustering is in the roadmap for sometime this year. 
In the meantime, there is Fault Tolerance (PR just merged today) and soon Static Channels (allowing channels partitioning) will soon be available.

Ivan.
Reply all
Reply to author
Forward
0 new messages