Google Pub/Sub Messaging Configuration

Hono can be configured to support Google Pub/Sub as the messaging infrastructure. The Pub/Sub client used for this purpose can be configured by means of operating system environment variables.

Supporting Google Pub/Sub, Hono must run on Google Kubernetes Engine to authenticate to the Google Pub/Sub API. To authenticate to the Google Pub/Sub API, Workload Identity is used and has to be configured as described in the Google Cloud Documentation.

Warning

Support for Google Pub/Sub based messaging infrastructure is considered experimental and may change without further notice.

Publisher and Subscriber Configuration

The org.eclipse.hono.client.pubsub.publisher.CachingPubSubPublisherFactory factory can be used to create Pub/Sub publishers for Hono’s Pub/Sub based APIs. The org.eclipse.hono.client.pubsub.subscriber.CachingPubSubSubscriberFactory factory can be used to create Pub/Sub subscribers for Hono’s Pub/Sub based APIs.

Please refer to the Quarkus Google Cloud Services extension documentation for details regarding configuration of the Pub/Sub client.

Configuring Tenants to use Pub/Sub based Messaging

Hono’s components by default support using Kafka based messaging infrastructure to transmit messages hence and forth between devices and applications. Hono also supports using Pub/Sub as the messaging infrastructure either as a replacement for or as an alternative in addition to the Kafka based infrastructure.

In most cases Hono’s components will be configured to use either Pub/Sub, AMQP 1.0 or Kafka based messaging infrastructure. However, in cases where more than one type of infrastructure is being used, Hono’s components need to be able to determine, which infrastructure should be used for messages of a given tenant. For this purpose, the configuration properties registered for a tenant support the ext/messaging-type property which can have a value of either pubsub, amqp or kafka.

The following example shows a tenant that is configured to use the Pub/Sub based messaging infrastructure:

{
  "tenant-id": "TEST_TENANT",
  "enabled": true,
  "ext": {
    "messaging-type": "pubsub"
  }
}

If not explicitly set, the ext/messaging-type property’s value is kafka which indicates that Kafka is to be used for the tenant.

Info

If an adapter is configured to connect to only one type of messaging infrastructure, the tenant specific messaging type configuration is ignored.

Used Topics and Subscriptions

For Telemetry, Event and Command & Control Messages

The Hono components publish messages to the following, tenant-specific Pub/Sub topics, from which downstream applications can create subscriptions and consume the messages:

Topic name Description
projects/${google_project_id}/topics/${tenant_id}.telemetry Topic for telemetry messages.
projects/${google_project_id}/topics/${tenant_id}.event Topic for event messages.
projects/${google_project_id}/topics/${tenant_id}.command_response Topic for command response messages.

For command & control messages published by downstream applications, the following topic is used:

Topic name Description
projects/${google_project_id}/topics/${tenant_id}.command Topic for command & control messages.

For command & control messages consumed by the Hono command router, the following subscription is used:

Subscription name Description
projects/${google_project_id}/subscriptions/${tenant_id}.command Subscription for command & control messages.

The above topics and subscriptions must be created in advance.

For Hono internal messages

For messages published only by Hono components, the following topics are used:

Topic name Description
projects/${google_project_id}/topics/${adapter_instance_id}.command_internal Topic used for routing of command & control messages between Hono components.
projects/${google_project_id}/topics/registry-tenant.notification Topic used for notification messages between Hono components about changes to tenant registration data.
projects/${google_project_id}/topics/registry-device.notification Topic used for notification messages between Hono components about changes to device registration data.

For messages consumed only by Hono components, the following subscriptions are used:

Subscription name Description
projects/${google_project_id}/subscriptions/${adapter_instance_id}.command_internal Subscription used for routing of command & control messages between Hono components.
projects/${google_project_id}/subscriptions/registry-tenant.notification Subscription used for notification messages between Hono components about changes to tenant registration data.
projects/${google_project_id}/subscriptions/registry-device.notification Subscription used for notification messages between Hono components about changes to device registration data.

The projects/${google_project_id}/topics/${adapter_instance_id}.command_internal topic and the projects/${google_project_id}/subscriptions/${adapter_instance_id}.command_internal subscription name contains a unique identifier as prefix, created dynamically on protocol adapter start. Therefore, this topic cannot be created in advance. It is created by a Pub/Sub based admin client in the protocol adapters.

The projects/${google_project_id}/topics/${PREFIX}.notification topics and subscriptions need to be created in advance.