private Task SendMessageAsync(IntegrationEvent @event) { if (disposed) { throw new ObjectDisposedException(nameof(topicClients)); } var publisherInfo = GetPublisherInfo(@event.GetType()); ITopicClient topicClient; lock (thisLock) { if (topicClients.ContainsKey(publisherInfo.TopicName)) { topicClient = topicClients[publisherInfo.TopicName]; } else { topicClient = topicClientFactory.Create(configuration.ServiceBusConnectionString, publisherInfo.TopicName, publisherInfo.RetryPolicy); topicClients.Add(publisherInfo.TopicName, topicClient); } } var message = CreateServiceBusMessage(@event); return(topicClient.SendAsync(message)); }
public async Task Publish <TEvent>(TEvent @event) where TEvent : class { var topicName = _azureServiceBusPublisherConfiguration.TopicName; var policyName = _azureServiceBusPublisherConfiguration.PolicyName; var topicClient = await _topicClientFactory.Create(topicName, policyName); var message = _messageFactory.Create(@event); await topicClient.SendAsync(message); }
public void PublishEventsAsync_WithValidInput_SendMessages() { // Arrange var events = fixture.CreateMany <FakeEvent1>(); var topicClient = fixture.Create <ITopicClient>(); topicClientFactory.Create( configuration.ServiceBusConnectionString, TopicName1, RetryPolicyBase.DefaultRetry).Returns(topicClient); // Act sut.PublishEventsAsync(events).Wait(); // Assert topicClient.Received(3).SendAsync(Arg.Any <Message>()); }