public bool PublishEvent(IntegrationEvent @event) { RabbitMqTopicModel topicModel = _integrationEventTopicMapping.GetPublishedTopic(@event.GetType().Name); if (topicModel == null) { return(false); } _queueProcessor.PublishMessageToExchange(topicModel.Exchange, topicModel.RoutingKey, @event); return(true); }
protected async Task <bool> Publish(IntegrationEventLogEntry entry) { int count = 0; bool publishSucceeded = false; var eventTypeName = GetRelativeEventTypeName(entry.EventTypeName); var topicModel = _topicMapping.GetPublishedTopic(eventTypeName); if (topicModel == null) { return(false); } entry.UpdateState(EventStateEnum.InProgress); await _context.SaveChangesAsync(); while (!publishSucceeded && count <= RetryTimes) { try { publishSucceeded = _queueProcessor.PublishPlainMessageToExchange(topicModel.Exchange, topicModel.RoutingKey, entry.Content); } catch (Exception ex) { publishSucceeded = false; } } if (publishSucceeded) { entry.UpdateState(EventStateEnum.Published); await _context.SaveChangesAsync(); } else { entry.UpdateState(EventStateEnum.PublishedFailed); await _context.SaveChangesAsync(); } return(publishSucceeded); }