Classes for sending and listening to a message bus. Uses AMQPNETLITE (AMQP 1. 0 protocol).
- Authorization keys cannot contain '/'. They must be regenerated if they do. AMQPNETLITE does not like that value.
- I found inconsistent behavior if the topic and queue were created using the AzureSB UI. I had success creating the topics, subscriptions, queues using ServiceBusExplorer (https://github.com/paolosalvatori/ServiceBusExplorer/releases)
- Names of queues cannot be single worded. Should be multipart (eg. auth.queue).
- The forward to setting for the topic subscription is not visible in the azure UI. You can use ServiceBusExplorer to set that field.
- for the following configuration settings for the test project with a TestEvent object
"Publisher.Settings": {
"Protocol": "amqps",
"Namespace": "namespace.servicebus.windows.net",
"Policy": "Send",
"Key": "44CharBASE64EncodedNoSlashes",
"AppName": "test.publisher",
"Topic": "topic.",
"Durable": "0"
},
"Receiver.Settings": {
"Protocol": "amqps",
"Namespace": "namespace.servicebus.windows.net",
"Policy": "Listen",
"Key": "44CharBASE64EncodedNoSlashes",
"AppName": "test.receiver",
"Queue": "queue.testReceive",
"Durable": "0"
}
(for test default settings from Service Bus Explorer are fine unless specified below)
- Azure Service Bus Components:
- a queue named queue.TestReceive
- new authorization rule for queue
- claimType = SharedAccessKey
- claimValue = none
- KeyName = "Listen"
- Primary/Secondary Key = 44 Char BASE64 encoded string (33 char unencoded and remember no '/')
- Manage - off
- Send - off
- Listen - on
- new authorization rule for queue
- a topic named topic.TestEvent
- new authorization rule for topic
- claimType = SharedAccessKey
- claimValue = none
- KeyName = "Send"
- Primary/Secondary Key = 44 Char BASE64 encoded string (33 char unencoded and remember no '/')
- Manage - off
- Send - on
- Listen - off
- new authorization rule for topic
- a subscription to topic.TestEvent named subscription.TestEvent
- The "Forward To" setting for this subscription needs to be set to queue.TestReceive
- a queue named queue.TestReceive
What To Do:
- will probably want to set deduplication at the message broker since same messageId will be used
- will need to generate ef migration after adding following to OnModelCreating method in dbcontext class:
- modelBuilder.AddDomainEventOutbox();
- https://github.com/cortside/cortside.webapistarter/blob/outbox/src/Cortside.WebApiStarter.Data/Migrations/20210228035338_DomainEventOutbox.cs
- register IDomainEventOutboxPublisher AND IDomainEventPublisher
- use IDomainEventOutboxPublisher in classes that will publish to the outbox
- SaveChanges after calling PublishAsync or ScheduleAsync -- and make part of transaction or workset in db so that publish becomes atomic with db changes
- OutboxHostedService needs IDomainEventPublisher to actually publish to message broker
- register OutboxHostedService to publish messages from db to broker
- if publishing an entity id in message, might need to add a using around the work with a transaction and call savechanges twice if the entity id is assigned by the db
- DomainEventPublisher change in publish method
- SendAsync to PublishAsync
- ScheduleMessageAsync to ScheduleAsync
- overrides for both PublishAsync and ScheduleAsync use EventProperties for overrides that allowed for EventType or Topic
- namespaces all dropped common
- make sure to check logging overrides for namespaces that might have changed
- namespace for handler interface changed to be in Handlers
- namespace for ReceiverHostedService changed to be in Hosting
- ReceiverHostedServiceSettings.Disabled changed to Enabled
- ReceiverHostedServiceSettings.TimedInterval should not be specified in seconds, not milliseconds
- IDomainEventHandler HandleAsync now has return value of HandlerResultEnum
- To keep current functionality, return HandlerResultEnum.Success and let uncaught exceptions trigger HandlerResultEnum.Failure result
- Publisher uses Logger instead of Logger
- Reciever uses Logger instead of Logger
- ServiceBusPublisherSettings renamed to DomainEventPublisherSettings
- changed Address to Topic
- ServiceBusReceiverSettings renamed to DomainEventReceiverSettings
- changed Address to Queue
- receiverHostedServiceSettings now has property for message type lookup dictionary named MessageTypes
- publisher should return published message information -- at least messageId -- would make debugging easier
- allow publisher to be used to publish multiple events withing a using statement without having to create new connection for each publish