Last active
February 22, 2020 04:08
-
-
Save shijuvar/1a297127b33bee0220dc21f601a5906f to your computer and use it in GitHub Desktop.
Subscriber Client with queue group, of NATS Publish-Subscribe messaging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ( | |
queue = "Order.OrdersCreatedQueue" | |
subject = "Order.OrderCreated" | |
) | |
func main() { | |
// Create server connection | |
natsConnection, _ := nats.Connect(nats.DefaultURL) | |
log.Println("Connected to " + nats.DefaultURL) | |
// Subscribe to subject | |
natsConnection.QueueSubscribe(subject, queue, func(msg *nats.Msg) { | |
eventStore := pb.EventStore{} | |
err := proto.Unmarshal(msg.Data, &eventStore) | |
if err == nil { | |
// Handle the message | |
log.Printf("Subscribed message in Worker 1: %+v\n", eventStore) | |
} | |
}) | |
// Keep the connection alive | |
runtime.Goexit() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment