具有不同消息类型的Google Cloud Pub/Sub [英] Google Cloud Pub/Sub with different message types

查看:70
本文介绍了具有不同消息类型的Google Cloud Pub/Sub的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在同一应用程序中,我发送格式完全不同且完全不相关的不同消息类型.解决此问题的最佳实践是什么?

我在这里看到两种不同的方法:

  1. 应用程序级别的过滤器,这意味着我在同一个合并器(相同订阅)上收到所有消息
  2. 创建一个新的订阅,这意味着该应用程序将有两个正在运行的Puller(每种消息类型一个)

解决方案

您用2点回答了您的问题.如果消息格式具有完全不同的格式并且完全不相关,则意味着应将它们分开.在应用程序层对其进行过滤没有任何优势.

发布订阅"模型允许将消息异步广播到系统的不同部分.消息主题是消息队列的兄弟姐妹,它提供了一种广播异步事件通知的机制,以及允许软件组件连接到主题以便发送和接收那些消息的端点.要广播消息,称为发布者的组件只需将消息推送到主题即可.现在,主题和订阅之间的区别在于,一个主题可以具有多个订阅,但是给定的订阅属于一个主题.

总结:

  • 要发布消息时,请使用主题.
  • 要使用邮件时使用订阅.

Within the same application I send different message types that have a completely different format and that are totally unrelated. What is the best practice to tackle this problem?

I see two different approaches here :

  1. Filter at application level, which means I receive all messages on the same puller (same subscription)
  2. Create a new subscription, this means the application will have two pullers running (one for each message type)

解决方案

You anwsered your question with 2. point. If the message format have completely different format and that are totally unrelated, that means they should be separated. There's no advantage of filtering them on application layer. Topics/subscriptions model is made exactly for this purpose.

The difference between topic and a subscription might be confusing. So let me describe that as well.

First the concepts Pub Sub:

  • Topic: A named resource to which messages are sent by publishers. In a pub/sub model, any message published to a topic is immediately received by all of the subscribers to the topic.
  • Subscription: A named resource representing the stream of messages from a single, specific topic, to be delivered to the subscribing application.
  • Message: The combination of data and (optional) attributes that a publisher sends to a topic and is eventually delivered to subscribers.
  • Message attribute: A key-value pair that a publisher can define for a message.

This diagram demonstrates Pub/Sub model

The Publish Subscribe model allows messages to be broadcast to different parts of a system asynchronously. A sibling to a message queue, a message topic provides a mechanism to broadcast asynchronous event notifications, and endpoints that allow software components to connect to the topic in order to send and receive those messages. To broadcast a message, a component called a publisher simply pushes a message to the topic. Now the difference between topic and subscription is a topic can have multiple subscriptions, but a given subscription belongs to a single topic.

To sum up:

  • Use a Topic when you would like to publish messages.
  • Use a Subscription when you would like to consume messages.

这篇关于具有不同消息类型的Google Cloud Pub/Sub的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆