{"id":375,"date":"2026-05-12T09:00:00","date_gmt":"2026-05-12T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/"},"modified":"2026-10-10T21:21:20","modified_gmt":"2026-10-10T15:51:20","slug":"go-nats-messaging","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/","title":{"rendered":"Go NATS Messaging: Publish, Subscribe and Request"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go NATS gives your services a fast, simple way to send messages to each other without calling each other directly. In this post, you will learn the three core NATS patterns: publish and subscribe, queue groups, and request and reply. Then we will build an order system where one event reaches several services at once.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the last two lessons, our chat hub and SSE broker lived inside one Go process. So they could not share messages across servers. That is exactly the gap a message system fills. For a refresher on goroutines, see <a href=\"https:\/\/smitabharat.com\/blog\/go-goroutines-beginners-guide\/\">Go goroutines explained for beginners<\/a>. Also, for clean exits, see <a href=\"https:\/\/smitabharat.com\/blog\/go-graceful-shutdown\/\">Go graceful shutdown<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Go NATS?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">NATS is an open source messaging server, and <code>nats.go<\/code> is its official Go client. A service publishes a message to a named topic, called a subject. Then every service that subscribed to that subject receives a copy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, think of a group announcement on a school notice board. The teacher pins one notice, and every student who checks the board sees it. Also, the teacher does not need to know who is reading. Similarly, a publisher in Go NATS never needs to know who the subscribers are.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The NATS server is a single small binary. As a result, you can run it on your laptop in seconds and in production on a few small machines.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go NATS Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When services call each other directly over HTTP, they become tightly linked. If the email service is down, the order service fails too. However, with a message system in the middle, each service only talks to NATS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are common reasons teams add Go NATS to a backend.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Fan-out events<\/strong>: one &#8220;order created&#8221; event goes to the email, invoice and analytics services together.<\/li>\n\n\n\n<li><strong>Load sharing<\/strong>: three copies of a worker split the jobs between them automatically.<\/li>\n\n\n\n<li><strong>Fast internal calls<\/strong>: request and reply over NATS replaces many small HTTP calls.<\/li>\n\n\n\n<li><strong>Scaling real-time apps<\/strong>: chat or SSE servers share live messages through one subject.<\/li>\n\n\n\n<li><strong>Loose coupling<\/strong>: you can add a new subscriber later without changing the publisher.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In short, Go NATS lets services react to events instead of waiting on each other.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Go NATS Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">First, every service opens one long-lived TCP connection to the NATS server. Next, subscribers tell the server which subjects they care about. Then, when a publisher sends a message, the server forwards it to every matching subscriber. Finally, each client library calls your handler function in its own goroutine.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-diagram-1-1024x640.png\" alt=\"Go NATS diagram showing one published order event delivered to three subscribed services\" class=\"wp-image-352\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">An order service publishes one message on orders.created, and the NATS server delivers a copy to every subscribed service.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">By default, core NATS is &#8220;fire and forget&#8221;. So if no one is listening at that moment, the message is simply dropped. For messages you must never lose, NATS adds a storage layer called JetStream. We look at it later in this post.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Key Parts of Go NATS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In practice, a few building blocks cover almost everything you will do with Go NATS. So once you know them, most NATS code reads easily.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Subjects and Wildcards<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A subject is a string made of tokens separated by dots, such as <code>orders.created<\/code>. Also, subscribers can use two wildcards. This table shows how they match.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Subject pattern<\/th><th>Matches<\/th><th>Does not match<\/th><\/tr><\/thead><tbody><tr><td><code>orders.created<\/code><\/td><td><code>orders.created<\/code> only<\/td><td><code>orders.paid<\/code><\/td><\/tr><tr><td><code>orders.*<\/code><\/td><td><code>orders.created<\/code>, <code>orders.paid<\/code><\/td><td><code>orders.eu.created<\/code><\/td><\/tr><tr><td><code>orders.&gt;<\/code><\/td><td><code>orders.created<\/code>, <code>orders.eu.created<\/code><\/td><td><code>payments.created<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In other words, <code>*<\/code> matches exactly one token, while <code>&gt;<\/code> matches one or more tokens at the end.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Publish and Subscribe<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>nc.Publish(subject, data)<\/code> sends bytes to a subject. Meanwhile, <code>nc.Subscribe(subject, handler)<\/code> registers a function that runs for every message on that subject.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Queue Groups<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When several subscribers join the same queue group, NATS delivers each message to only one of them. So you get automatic load balancing without a separate load balancer.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Request and Reply<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>nc.Request<\/code> publishes a message and waits for one answer. On the other side, the responder calls <code>m.Respond<\/code>. In fact, this works like an HTTP call, but through NATS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Core NATS vs JetStream<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">NATS comes in two layers. The table below compares them so you can pick the right one.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Core NATS<\/th><th>JetStream<\/th><\/tr><\/thead><tbody><tr><td>Storage<\/td><td>None, memory only<\/td><td>Messages saved to disk<\/td><\/tr><tr><td>Missed messages<\/td><td>Lost if no one listens<\/td><td>Kept until read<\/td><\/tr><tr><td>Delivery<\/td><td>At most once<\/td><td>At least once, with acks<\/td><\/tr><tr><td>Speed<\/td><td>Fastest<\/td><td>Slightly slower<\/td><\/tr><tr><td>Setup<\/td><td>Nothing extra<\/td><td>Create a stream first<\/td><\/tr><tr><td>Good for<\/td><td>Live updates, requests<\/td><td>Orders, payments, jobs<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-diagram-2-1024x640.png\" alt=\"Go NATS diagram showing a queue group sharing six orders between three workers\" class=\"wp-image-353\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">With a queue group, NATS gives each message to only one worker, so three workers share the load.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So when should you use which? Use core NATS for live data where a missed message does not hurt. On the other hand, use JetStream when every message must be processed, such as an order or a payment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hands-On: An Order System with Go NATS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s build a small Go NATS system. First, an order service publishes events. Then an email service and an analytics service both receive them. Finally, an inventory service answers stock questions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Run the NATS Server<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The quickest way is Docker. Alternatively, download the <code>nats-server<\/code> binary for your system and run it directly.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d --name nats -p 4222:4222 nats:latest -js<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>-js<\/code> flag turns on JetStream. Then add the Go client to your module.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go get github.com\/nats-io\/nats.go<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Publish and Subscribe<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This program starts two subscribers on the same subject and then publishes one order event.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func main() {\n\tnc, err := nats.Connect(nats.DefaultURL)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer nc.Drain()\n\n\t\/\/ Two different services listen to the same subject.\n\tnc.Subscribe(\"orders.created\", func(m *nats.Msg) {\n\t\tfmt.Printf(\"email service got: %s\\n\", m.Data)\n\t})\n\tnc.Subscribe(\"orders.*\", func(m *nats.Msg) {\n\t\tfmt.Printf(\"analytics got %s: %s\\n\", m.Subject, m.Data)\n\t})\n\n\t\/\/ The order service publishes one event.\n\torder := []byte(`{\"id\":1042,\"total\":499}`)\n\tif err := nc.Publish(\"orders.created\", order); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tnc.Flush()\n\ttime.Sleep(100 * time.Millisecond) \/\/ give handlers time to print\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>nats.DefaultURL<\/code> is <code>nats:\/\/127.0.0.1:4222<\/code>. Also, <code>Flush<\/code> waits until the server has received everything we sent. Finally, <code>Drain<\/code> lets pending messages finish before the connection closes, which is the clean way to shut down.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Both subscribers receive the same event, so the output looks like this. The two lines may appear in either order, because each handler runs separately.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>email service got: {\"id\":1042,\"total\":499}\nanalytics got orders.created: {\"id\":1042,\"total\":499}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Share Work with a Queue Group<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now imagine three copies of the email service. We want each email sent only once.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for i := 1; i &lt;= 3; i++ {\n\tworker := i\n\tnc.QueueSubscribe(\"orders.created\", \"emailers\", func(m *nats.Msg) {\n\t\tfmt.Printf(\"worker %d sends email for %s\\n\", worker, m.Data)\n\t})\n}\nfor id := 1; id &lt;= 6; id++ {\n\tnc.Publish(\"orders.created\", []byte(fmt.Sprintf(\"order-%d\", id)))\n}\nnc.Flush()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">All three workers join the queue group <code>emailers<\/code>. As a result, each of the six orders goes to exactly one worker. The split is random, so you might see worker 2 handle three orders while worker 3 handles one.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Request and Reply<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, the inventory service answers questions. The order service asks and waits up to two seconds.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Inventory service: answers stock questions.\nnc.Subscribe(\"inventory.check\", func(m *nats.Msg) {\n\tm.Respond([]byte(\"in stock: \" + string(m.Data)))\n})\n\n\/\/ Order service: asks and waits for the answer.\nreply, err := nc.Request(\"inventory.check\", []byte(\"book-7\"), 2*time.Second)\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Println(\"reply:\", string(reply.Data))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With the responder running, the program prints one line.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>reply: in stock: book-7<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">However, if no service listens on <code>inventory.check<\/code>, the request fails at once with <code>nats: no responders available for request<\/code>. And if a responder exists but is too slow, you get <code>nats: timeout<\/code> instead.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Keep Go NATS Messages with JetStream<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For orders, losing a message is not acceptable. So we store them in a JetStream stream. The newer <code>jetstream<\/code> package inside <code>nats.go<\/code> makes this short.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>js, err := jetstream.New(nc)\nif err != nil {\n\tlog.Fatal(err)\n}\nctx := context.Background()\n\n\/\/ A stream stores every message on orders.&gt; subjects.\n_, err = js.CreateStream(ctx, jetstream.StreamConfig{\n\tName:     \"ORDERS\",\n\tSubjects: []string{\"orders.&gt;\"},\n})\nif err != nil {\n\tlog.Fatal(err)\n}\n\nack, err := js.Publish(ctx, \"orders.created\", []byte(`{\"id\":1042}`))\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Println(\"stored in\", ack.Stream, \"at sequence\", ack.Sequence)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Unlike core <code>Publish<\/code>, this call waits for the server to confirm that the message is saved. So <code>ack.Sequence<\/code> tells you its position in the stream. On a fresh stream, the first message gets sequence 1, and the program prints <code>stored in ORDERS at sequence 1<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To read from the stream, a service creates a durable consumer and acknowledges each message after it finishes the work. As a result, if the service crashes halfway, Go NATS JetStream delivers the message again later.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go NATS<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Exiting before messages arrive<\/strong>: <code>main<\/code> returns and handlers never run. So call <code>Flush<\/code> and keep the program alive, or use <code>Drain<\/code> on shutdown.<\/li>\n\n\n\n<li><strong>Expecting core NATS to store messages<\/strong>: messages sent while a service is down are lost. Use JetStream for anything important.<\/li>\n\n\n\n<li><strong>Forgetting queue groups<\/strong>: three worker copies each send the same email three times. Use <code>QueueSubscribe<\/code> with a shared group name.<\/li>\n\n\n\n<li><strong>Slow handlers<\/strong>: a long handler delays later messages on that subscription. Instead, hand heavy work to a worker pool.<\/li>\n\n\n\n<li><strong>No timeout on requests<\/strong>: a missing responder can block your flow. Always pass a sensible timeout to <code>Request<\/code>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go NATS<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Name subjects like paths<\/strong>, such as <code>orders.eu.created<\/code>, because wildcards then work nicely.<\/li>\n\n\n\n<li><strong>Send JSON or protobuf payloads<\/strong>, so every language can read them.<\/li>\n\n\n\n<li><strong>Use one connection per process<\/strong>, since a single NATS connection handles many subscriptions.<\/li>\n\n\n\n<li><strong>Drain on shutdown<\/strong>, as it finishes in-flight messages before closing.<\/li>\n\n\n\n<li><strong>Pick JetStream for business events<\/strong>, because acks and storage protect against lost messages.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Connect this to the SSE tracker from the previous post. Subscribe to <code>orders.*<\/code> in the SSE server and pass every NATS message to <code>broker.publish<\/code>. Then run two SSE servers and check that both browsers receive every update.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hint: subscribe once at startup, outside the HTTP handlers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages cover the client API and the server features in detail.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/github.com\/nats-io\/nats.go\">nats.go package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/docs.nats.io\/nats-concepts\/subjects\">NATS docs: Subject-based messaging<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/docs.nats.io\/nats-concepts\/jetstream\">NATS docs: JetStream<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go NATS sends messages between services through a NATS server.<\/li>\n\n\n\n<li>Subjects use dots, and <code>*<\/code> and <code>&gt;<\/code> act as wildcards.<\/li>\n\n\n\n<li>Plain subscribers each get a copy, while a queue group shares the work.<\/li>\n\n\n\n<li><code>Request<\/code> and <code>Respond<\/code> give you request and reply with a timeout.<\/li>\n\n\n\n<li>Core NATS is fire and forget, and JetStream adds storage and acks.<\/li>\n\n\n\n<li>Call <code>Drain<\/code> on shutdown so pending messages are not lost.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Messages move data between services. However, most services also need to store it, so we will add a database next. Next, we will connect Go to PostgreSQL using the pgx driver.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next lesson: <a href=\"https:\/\/smitabharat.com\/blog\/go-postgresql-pgx\/\">Go PostgreSQL with pgx: A Practical Guide<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Go NATS gives your services a fast, simple way to send messages to each other without calling each other directly. In this post, you&hellip;<\/p>\n","protected":false},"author":1,"featured_media":351,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[11,69,23,21],"swapz_series":[],"class_list":["post-375","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-lang","tag-go-nats","tag-go-tutorial","tag-golang-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go NATS Messaging: Publish, Subscribe and Request<\/title>\n<meta name=\"description\" content=\"Learn Go NATS messaging with simple examples: publish and subscribe, wildcards, queue groups, request and reply, and when to use JetStream.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go NATS Messaging: Publish, Subscribe and Request\" \/>\n<meta property=\"og:description\" content=\"Learn Go NATS messaging with simple examples: publish and subscribe, wildcards, queue groups, request and reply, and when to use JetStream.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-05-12T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-10T15:51:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-nats-messaging\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-nats-messaging\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go NATS Messaging: Publish, Subscribe and Request\",\"datePublished\":\"2026-05-12T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:51:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-nats-messaging\\\/\"},\"wordCount\":1469,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-nats-messaging\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-nats-messaging-featured.png\",\"keywords\":[\"Go Lang\",\"Go NATS\",\"Go Tutorial\",\"Golang Basics\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-nats-messaging\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-nats-messaging\\\/\",\"name\":\"Go NATS Messaging: Publish, Subscribe and Request\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-nats-messaging\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-nats-messaging\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-nats-messaging-featured.png\",\"datePublished\":\"2026-05-12T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:51:20+00:00\",\"description\":\"Learn Go NATS messaging with simple examples: publish and subscribe, wildcards, queue groups, request and reply, and when to use JetStream.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-nats-messaging\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-nats-messaging\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-nats-messaging\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-nats-messaging-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-nats-messaging-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go NATS featured image: cards for publish, queue groups and request reply\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-nats-messaging\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go NATS Messaging: Publish, Subscribe and Request\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go NATS Messaging: Publish, Subscribe and Request","description":"Learn Go NATS messaging with simple examples: publish and subscribe, wildcards, queue groups, request and reply, and when to use JetStream.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/","og_locale":"en_US","og_type":"article","og_title":"Go NATS Messaging: Publish, Subscribe and Request","og_description":"Learn Go NATS messaging with simple examples: publish and subscribe, wildcards, queue groups, request and reply, and when to use JetStream.","og_url":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-05-12T03:30:00+00:00","article_modified_time":"2026-10-10T15:51:20+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go NATS Messaging: Publish, Subscribe and Request","datePublished":"2026-05-12T03:30:00+00:00","dateModified":"2026-10-10T15:51:20+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/"},"wordCount":1469,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-featured.png","keywords":["Go Lang","Go NATS","Go Tutorial","Golang Basics"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/","url":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/","name":"Go NATS Messaging: Publish, Subscribe and Request","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-featured.png","datePublished":"2026-05-12T03:30:00+00:00","dateModified":"2026-10-10T15:51:20+00:00","description":"Learn Go NATS messaging with simple examples: publish and subscribe, wildcards, queue groups, request and reply, and when to use JetStream.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-nats-messaging\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-nats-messaging-featured.png","width":2400,"height":1260,"caption":"Go NATS featured image: cards for publish, queue groups and request reply"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go NATS Messaging: Publish, Subscribe and Request"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=375"}],"version-history":[{"count":1,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/375\/revisions"}],"predecessor-version":[{"id":385,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/375\/revisions\/385"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/351"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=375"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}