public override void WhenConnected() { // we have only one consumer per connection so global is ok Channel.BasicQos(0, (ushort)_stage.BufferSize, false); var consumerCallback = GetAsyncCallback <IncomingMessage>(HandleDelivery); var shutdownCallback = GetAsyncCallback <ShutdownEventArgs>(args => { if (args != null) { FailStage(ShutdownSignalException.FromArgs(args)); } else { CompleteStage(); } }); _amqpSourceConsumer = new DefaultConsumer(consumerCallback, shutdownCallback); if (Settings is NamedQueueSourceSettings) { var namedSourceSettings = (NamedQueueSourceSettings)Settings; SetupNamedQueue(namedSourceSettings); } else if (Settings is TemporaryQueueSourceSettings) { var tempSettings = (TemporaryQueueSourceSettings)Settings; SetupTmeporaryQueue(tempSettings); } }
public override void WhenConnected() { var shutdownCallback = GetAsyncCallback <(string consumerTag, ShutdownEventArgs args)>(tuple => { if (tuple.args != null) { var exception = ShutdownSignalException.FromArgs(tuple.args); var appException = new ApplicationException( $"Consumer {_queueName} with consumerTag {tuple.consumerTag} shutdown unexpectedly", exception); _promise.SetException(appException); FailStage(appException); } else { var appException = new ApplicationException( $"Consumer {_queueName} with consumerTag {tuple.consumerTag} shutdown unexpectedly"); _promise.SetException(appException); FailStage(appException); } }); Pull(_stage.In); // we have only one consumer per connection so global is ok Channel.BasicQos(0, (ushort)_stage.BufferSize, false); var consumerCallback = GetAsyncCallback <IncomingMessage>(HandleDelivery); _amqpSourceConsumer = new DefaultConsumer(consumerCallback, shutdownCallback); // Create an exclusive queue with a randomly generated name for use as the replyTo portion of RPC _queueName = Channel.QueueDeclare("", false, true, true).QueueName; Channel.BasicConsume(_queueName, false, _amqpSourceConsumer); _promise.TrySetResult(_queueName); }
public override void WhenConnected() { _shutdownCallback = GetAsyncCallback <ShutdownEventArgs>(args => { var exception = ShutdownSignalException.FromArgs(args); _promise.SetException(exception); FailStage(exception); }); Channel.ModelShutdown += OnChannelShutdown; Pull(_stage.In); }
public override void PreStart() { try { var factory = ConnectionFactoryFrom(Settings.ConnectionSettings); Connection = NewConnection(factory, Settings.ConnectionSettings); Channel = Connection.CreateModel(); ShutdownCallback = GetAsyncCallback <ShutdownEventArgs>(args => { if (args.Initiator != ShutdownInitiator.Application) { FailStage(ShutdownSignalException.FromArgs(args)); } }); Connection.ConnectionShutdown += OnConnectionShutdown; Channel.ModelShutdown += OnChannelShutdown; foreach (var declaration in Settings.Declarations) { switch (declaration) { case QueueDeclaration queueDeclaration: Channel.QueueDeclare(queueDeclaration.Name, queueDeclaration.Durable, queueDeclaration.Exclusive, queueDeclaration.AutoDelete, queueDeclaration.Arguments.ToDictionary(key => key.Key, val => val.Value)); break; case BindingDeclaration bindingDeclaration: Channel.QueueBind(bindingDeclaration.Queue, bindingDeclaration.Exchange, bindingDeclaration.RoutingKey ?? "", bindingDeclaration.Arguments.ToDictionary(key => key.Key, val => val.Value)); break; case ExchangeDeclaration exchangeDeclaration: Channel.ExchangeDeclare(exchangeDeclaration.Name, exchangeDeclaration.ExchangeType, exchangeDeclaration.Durable, exchangeDeclaration.AutoDelete, exchangeDeclaration.Arguments.ToDictionary(key => key.Key, val => val.Value)); break; } } WhenConnected(); } catch (Exception e) { OnFailure(e); throw; } }