components-contrib/pubsub
Joni Collinge 382f84f30c
Add support for Azure Service Bus sessions for topics (#2346)
* WIP: ASB sessions

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* WIP: Support ASB sessions

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Add metadata

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* remove dead code

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* lint

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Add sessionIdleTimeoutInSec md

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Support blank session IDs

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* If require sessions and no session id, set blank

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* move session config to per subscription metadata

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* add some unit tests

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* lint

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* remove auto blank session id

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* go mod tidy

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* add basic cert test

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* update comment

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* remove dead code

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* remove dead code

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Update certification test

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Add comment

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Add cert test for roundrobin

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* go mod tidy

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Update readme

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Use struct for NewSubscription to simplify parameters

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Address feedback

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Address feedback

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Only async receive

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* isTruthy on map without check

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Use if not select for context check

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Feedback

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* lint

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

Signed-off-by: Joni Collinge <jonathancollinge@live.com>
Signed-off-by: Bernd Verst <4535280+berndverst@users.noreply.github.com>
Co-authored-by: Yaron Schneider <schneider.yaron@live.com>
Co-authored-by: Bernd Verst <4535280+berndverst@users.noreply.github.com>
Co-authored-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com>
2023-01-06 09:59:26 -08:00
..
aws/snssqs feature: add context to lock&pubsub API 2022-12-14 19:37:24 +08:00
azure Add support for Azure Service Bus sessions for topics (#2346) 2023-01-06 09:59:26 -08:00
gcp/pubsub feature: add context to lock&pubsub API 2022-12-15 09:53:32 +08:00
hazelcast feature: add context to lock&pubsub API 2022-12-14 19:37:24 +08:00
in-memory feature: add context to lock&pubsub API 2022-12-15 09:53:32 +08:00
jetstream Make domain and prefix setup cleaner 2023-01-04 10:48:32 +01:00
kafka feature: add context to lock&pubsub API 2022-12-14 19:37:24 +08:00
kubemq feature: add context to lock&pubsub API 2022-12-15 09:53:32 +08:00
mqtt Use message's retain property to cover meta's (#2377) 2023-01-04 15:05:25 -08:00
natsstreaming feature: add context to lock&pubsub API 2022-12-15 09:53:32 +08:00
pulsar feature: add context to lock&pubsub API 2022-12-15 09:53:32 +08:00
rabbitmq Merge branch 'master' into feat/rabbitmq-tls 2022-12-19 15:31:47 -08:00
redis feature: add context to lock&pubsub API 2022-12-19 09:11:53 +08:00
rocketmq feature: add context to lock&pubsub API 2022-12-15 09:53:32 +08:00
solace/amqp Update of amqp go library 2022-12-28 23:28:25 -05:00
README.md middleware: changes wasm basic to use waPC (#1833) 2022-09-13 17:12:59 -07:00
concurrency.go update license to Apache v2.0 (#1406) 2022-01-04 19:53:31 -08:00
concurrency_test.go update license to Apache v2.0 (#1406) 2022-01-04 19:53:31 -08:00
envelope.go Merge branch 'master' into feature/pubsub-batching 2022-09-27 08:15:37 +05:30
envelope_test.go Add time to CloudEvent automatically if not present (#2123) 2022-09-26 14:44:57 -07:00
feature.go Added pubsub.FeatureSubscribeWildcards capability (#1887) 2022-07-18 18:04:59 -07:00
metadata.go fix typo in comment 2022-10-27 20:37:35 -07:00
pubsub.go Merge remote-tracking branch 'upstream/master' into optimize-bulkpubres-struct 2022-12-20 23:04:19 +05:30
requests.go Update EntryID to EntryId 2022-09-29 15:49:45 +05:30
responses.go changed to failed entries for bulk publish response 2022-12-13 16:22:45 +05:30
responses_test.go changed to failed entries for bulk publish response 2022-12-13 16:22:45 +05:30
tls.go Optimize code according to lint 2022-11-20 15:33:53 +08:00
tls_test.go Optimize code according to lint 2022-11-20 15:33:53 +08:00

README.md

Pub Sub

Pub Sub components provide a common way to interact with different message bus implementations to achieve reliable, high-scale scenarios based on event-driven async communications, while allowing users to opt-in to advanced capabilities using defined metadata.

Implementing a new Pub Sub

A compliant pub sub needs to implement the PubSub inteface included in the pubsub.go file.

Message TTL (or Time To Live)

Message Time to live is implemented by default in Dapr. A publishing application can set the expiration of individual messages by publishing it with the ttlInSeconds metadata. Components that support message TTL should parse this metadata attribute. For components that do not implement this feature in Dapr, the runtime will automatically populate the expiration attribute in the CloudEvent object if ttlInSeconds is present - in this case, Dapr will expire the message when a Dapr subscriber is about to consume an expired message. The expiration attribute is handled by Dapr runtime as a convenience to subscribers, dropping expired messages without invoking subscribers' endpoint. Subscriber applications that don't use Dapr, need to handle this attribute and implement the expiration logic.

If the pub sub component implementation can handle message TTL natively without relying on Dapr, consume the ttlInSeconds metadata in the component implementation for the Publish function. Also, implement the Features() function so the Dapr runtime knows that it should not add the expiration attribute to events.

Example:

import contribMetadata "github.com/dapr/components-contrib/metadata"

//...

func (c *MyComponent) Publish(req *pubsub.PublishRequest) error {
	//...
	ttl, hasTTL, _ := contribMetadata.TryGetTTL(req.Metadata)
	if hasTTL {
		//... handle ttl for component.
	}
	//...
	return nil
}

func (c *MyComponent) Features() []pubsub.Feature {
	// Tip: cache this list into a private property.
	// Simply return nil if component does not implement any addition features.
	return []pubsub.Feature{pubsub.FeatureMessageTTL}
}

For pub sub components that support TTL per topic or queue but not per message, there are some design choices:

  • Configure the TTL for the topic or queue as usual. Optionally, implement topic or queue provisioning in the Init() method, using the component configuration's metadata to determine the topic or queue TTL.
  • Let Dapr runtime handle ttlInSeconds for messages that want to expire earlier than the topic's or queue's TTL. So, applications can still benefit from TTL per message via Dapr for this scenario.

Note: as per the CloudEvent spec, timestamps (like expiration) are formatted using RFC3339.