components-contrib/pubsub
Gallardot 294dd75354
feat: kafka subpub and bindings support compression (#3676)
Signed-off-by: Gallardot <gallardot@apache.org>
Co-authored-by: Josh van Leeuwen <me@joshvanl.dev>
Co-authored-by: Yaron Schneider <schneider.yaron@live.com>
2025-05-16 10:45:37 -07:00
..
aws/snssqs feat(kafka): iam roles anywhere + assume role auth profiles (#3606) 2024-11-27 14:48:18 -08:00
azure Update go -> 1.24.1 & golangci-lint -> 1.64.6 (#3699) 2025-03-12 13:50:32 -07:00
gcp/pubsub Merge 1.14 into master (#3579) 2024-10-24 16:52:48 -07:00
in-memory Update go -> 1.24.1 & golangci-lint -> 1.64.6 (#3699) 2025-03-12 13:50:32 -07:00
jetstream Update go -> 1.24.1 & golangci-lint -> 1.64.6 (#3699) 2025-03-12 13:50:32 -07:00
kafka feat: kafka subpub and bindings support compression (#3676) 2025-05-16 10:45:37 -07:00
kubemq Update go -> 1.24.1 & golangci-lint -> 1.64.6 (#3699) 2025-03-12 13:50:32 -07:00
mqtt3 Update go -> 1.24.1 & golangci-lint -> 1.64.6 (#3699) 2025-03-12 13:50:32 -07:00
pulsar feat(pulsar): support subscribeInitialPosition on Pulsar consumer (#3700) 2025-04-29 11:11:53 -07:00
rabbitmq Update go -> 1.24.1 & golangci-lint -> 1.64.6 (#3699) 2025-03-12 13:50:32 -07:00
redis Adds Redis stream trimming by time(stream ID) (#3710) 2025-05-06 10:59:30 -07:00
rocketmq Update go -> 1.24.1 & golangci-lint -> 1.64.6 (#3699) 2025-03-12 13:50:32 -07:00
solace/amqp Merge 1.14 into master (#3579) 2024-10-24 16:52:48 -07: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 Switch to Go 1.21, Updates linter, updates workflows, adds sarama 1.42.1 (#3251) 2023-11-28 18:13:09 -08:00
envelope.go Retain cloudevent trace fields (#3080) 2023-08-14 13:40:14 -07:00
envelope_test.go Merge 1.14 into master (#3579) 2024-10-24 16:52:48 -07:00
feature.go Chore: use a single package for all Feature structs (#3278) 2024-01-08 09:07:10 -08:00
metadata.go fix typo in comment 2022-10-27 20:37:35 -07:00
pubsub.go Merge 1.14 into master (#3579) 2024-10-24 16:52:48 -07:00
requests.go Receiving events 2023-01-19 21:36:20 +00:00
responses.go changed to failed entries for bulk publish response 2022-12-13 16:22:45 +05:30
responses_test.go Switch to Go 1.21, Updates linter, updates workflows, adds sarama 1.42.1 (#3251) 2023-11-28 18:13:09 -08:00
tls.go Merge 1.14 into master (#3579) 2024-10-24 16:52:48 -07:00
tls_test.go Switch to Go 1.21, Updates linter, updates workflows, adds sarama 1.42.1 (#3251) 2023-11-28 18:13:09 -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.