public LineNotifyGateway( IOptions <AbpRabbitMqEventBusOptions> eventBusOptions, IServiceDefinitionStore serviceDefinitionStore, IChannelStore channelStore ) { this.eventBusOptions = eventBusOptions.Value; this.serviceDefinitionStore = serviceDefinitionStore; this.channelStore = channelStore; }
public void Initialize() { Consumer = MessageConsumerFactory.Create( new ExchangeDeclareConfiguration( AbpRabbitMqEventBusOptions.ExchangeName, type: AbpRabbitMqEventBusOptions.GetExchangeTypeOrDefault(), durable: true ), new QueueDeclareConfiguration( AbpRabbitMqEventBusOptions.ClientName, durable: true, exclusive: false, autoDelete: false ), AbpRabbitMqEventBusOptions.ConnectionName ); Consumer.OnMessageReceived(ProcessEventAsync); SubscribeHandlers(AbpDistributedEventBusOptions.Handlers); }
private void EnsureExchangeExists(IModel channel) { if (_exchangeCreated) { return; } try { channel.ExchangeDeclarePassive(AbpRabbitMqEventBusOptions.ExchangeName); } catch (Exception) { channel.ExchangeDeclare( AbpRabbitMqEventBusOptions.ExchangeName, AbpRabbitMqEventBusOptions.GetExchangeTypeOrDefault(), durable: true ); } _exchangeCreated = true; }
protected Task PublishAsync( string eventName, byte[] body, IBasicProperties properties, Dictionary <string, object> headersArguments = null, Guid?eventId = null) { using (var channel = ConnectionPool.Get(AbpRabbitMqEventBusOptions.ConnectionName).CreateModel()) { channel.ExchangeDeclare( AbpRabbitMqEventBusOptions.ExchangeName, AbpRabbitMqEventBusOptions.GetExchangeTypeOrDefault(), durable: true ); if (properties == null) { properties = channel.CreateBasicProperties(); properties.DeliveryMode = RabbitMqConsts.DeliveryModes.Persistent; } if (properties.MessageId.IsNullOrEmpty()) { properties.MessageId = (eventId ?? GuidGenerator.Create()).ToString("N"); } SetEventMessageHeaders(properties, headersArguments); channel.BasicPublish( exchange: AbpRabbitMqEventBusOptions.ExchangeName, routingKey: eventName, mandatory: true, basicProperties: properties, body: body ); } return(Task.CompletedTask); }