public void PublishMessage(string exchangeName, byte[] body) { var exchangeParam = new ExchangeParam { Exchange = exchangeName, Durable = false }; using (var channel = GetPublisherChannel(exchangeParam, null)) { var routingKey = exchangeParam.Exchange; channel.BasicPublish(exchangeParam.Exchange, routingKey, null, body); } }
public void SubscribeMessage <T>(string exchange, string queue, Func <Func <T?, Task> > resolve, ushort prefetchCount = DefaultPrefetchCount) { var exchangeParam = new ExchangeParam { Exchange = exchange, Durable = false }; var queueParam = new QueueParam { Queue = queue, Durable = false }; var channel = GetReceiverChannel(exchangeParam, queueParam, prefetchCount); ConsumeEvent(channel, resolve, queueParam.Queue); }
public void SubscribeEvent <T>(string exchange, string queue, Func <Action <T?> > resolve, ushort prefetchCount = DefaultPrefetchCount) { var exchangeParam = new ExchangeParam { Exchange = exchange }; var queueParam = new QueueParam { Queue = queue }; var channel = GetReceiverChannel(exchangeParam, queueParam, prefetchCount); ConsumeEvent(channel, resolve, queueParam.Queue); }
public async Task SubscribeMessageAsync <T>(string exchange, string queue, Func <Action <T?> > resolve, ushort prefetchCount = DefaultPrefetchCount) { var exchangeParam = new ExchangeParam { Exchange = exchange, Durable = false }; var queueParam = new QueueParam { Queue = queue, Durable = false }; var channel = GetReceiverAsyncChannel(exchangeParam, queueParam, prefetchCount); await ConsumeMessageAsync(channel, resolve, queueParam.Queue); }
public async Task SubscribeEventAsync <T>(string exchange, string queue, Func <Func <T?, Task> > resolve, ushort prefetchCount = DefaultPrefetchCount) { var exchangeParam = new ExchangeParam { Exchange = exchange }; var queueParam = new QueueParam { Queue = queue }; var channel = GetReceiverAsyncChannel(exchangeParam, queueParam, prefetchCount); await ConsumeEventAsync(channel, resolve, queueParam.Queue); }
public void ListenMessage <T>(Func <Func <T?, Task> > resolve, ushort prefetchCount = DefaultPrefetchCount) { var exchangeName = GetTypeName(typeof(T)); var queueName = $"{GetQueueName(resolve)}[{Guid.NewGuid()}]"; var exchangeParam = new ExchangeParam { Exchange = exchangeName, Durable = false }; var queueParam = new QueueParam { Queue = queueName, Durable = false, Exclusive = true, AutoDelete = true }; var channel = GetReceiverChannel(exchangeParam, queueParam, prefetchCount); ConsumeMessage(channel, resolve, queueParam.Queue); }
public void PublishEvent(string exchangeName, byte[] body) { var exchangeParam = new ExchangeParam { Exchange = exchangeName }; using (var channel = GetPublisherChannel(exchangeParam, null)) { var properties = channel.CreateBasicProperties(); properties.Persistent = true; var routingKey = exchangeParam.Exchange; channel.BasicPublish(exchangeParam.Exchange, routingKey, properties, body); } }
private IModel GetPublisherChannel(ExchangeParam exchangeParam, QueueParam?queueParam, string?routingKey = null) { var channel = _publishConn.CreateModel(); channel.ExchangeDeclare(exchange: exchangeParam.Exchange, type: exchangeParam.Type.ToString().ToLower(), durable: exchangeParam.Durable, autoDelete: exchangeParam.AutoDelete, arguments: exchangeParam.Arguments); if (queueParam is null) { return(channel); } channel.QueueDeclare(queue: queueParam.Queue, durable: queueParam.Durable, exclusive: queueParam.Exclusive, autoDelete: queueParam.AutoDelete, arguments: queueParam.Arguments); channel.QueueBind(queue: queueParam.Queue, exchange: exchangeParam.Exchange, routingKey: routingKey ?? queueParam.Queue); return(channel); }