public void MessageOrderTest(AcknowledgeMode consumerMode) { // Consumer SetUpEndPoint(1, false, true, TEST_ROUTING_KEY, consumerMode, false, ExchangeNameDefaults.DIRECT, true, false, null); Console.WriteLine("Starting producer thread"); Thread prodThread = new Thread(new ThreadStart(SendMessages)); prodThread.Start(); Thread.Sleep(2000); Console.WriteLine("Starting consuming"); for (int i = 0; i < MESSAGE_COUNT; i++) { if ((i % 10) == 0) { Console.WriteLine("Consuming message "+i); } ConsumeNMessages(1, "Msg"+i, testConsumer[1]); } prodThread.Join(); CloseEndPoint(0); CloseEndPoint(1); }
private void TestDurableSubscription(AcknowledgeMode ackMode) { // Create a topic with one producer and two consumers. SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, ackMode, false, ExchangeNameDefaults.TOPIC, true, false, null); SetUpEndPoint(1, false, true, TEST_ROUTING_KEY + testId, ackMode, false, ExchangeNameDefaults.TOPIC, true, false, null); SetUpEndPoint(2, false, true, TEST_ROUTING_KEY + testId, ackMode, false, ExchangeNameDefaults.TOPIC, true, true, "TestSubscription" + testId); Thread.Sleep(500); // Send messages and receive on both consumers. testProducer[0].Send(testChannel[0].CreateTextMessage("A")); ConsumeNMessagesOnly(1, "A", testConsumer[1]); ConsumeNMessagesOnly(1, "A", testConsumer[2]); // Detach one consumer. CloseEndPoint(2); // Send message and receive on one consumer. testProducer[0].Send(testChannel[0].CreateTextMessage("B")); ConsumeNMessagesOnly(1, "B", testConsumer[1]); // Re-attach consumer, check that it gets the messages that it missed. SetUpEndPoint(2, false, true, TEST_ROUTING_KEY + testId, ackMode, false, ExchangeNameDefaults.TOPIC, true, true, "TestSubscription" + testId); ConsumeNMessagesOnly(1, "B", testConsumer[2]); // Clean up any open consumers at the end of the test. CloseEndPoint(2); CloseEndPoint(1); CloseEndPoint(0); }
public CreateChannelFailoverSupport(AMQConnection connection, bool transacted, AcknowledgeMode acknowledgeMode, int prefetchHigh, int prefetchLow) { _connection = connection; _transacted = transacted; _acknowledgeMode = acknowledgeMode; _prefetchHigh = prefetchHigh; _prefetchLow = prefetchLow; }
private String ConsumeFromQueue(String queueName, bool noLocal, bool exclusive, AcknowledgeMode acknowledgeMode, String tag, bool browse) { FieldTable args = new FieldTable(); if(browse) { args["x-filter-no-consume"] = true; } args["x-filter-auto-close"] = false; AMQFrame basicConsume = BasicConsumeBody.CreateAMQFrame(_channelId, 0, queueName, tag, noLocal, acknowledgeMode == AcknowledgeMode.NoAcknowledge, exclusive, true, args); _replayFrames.Add(basicConsume); _connection.ProtocolWriter.Write(basicConsume); return tag; }
public static bool IsAutoAck(this AcknowledgeMode mode) { return(mode == AcknowledgeMode.NONE); }
/// <summary> Sets up the nth test end-point. </summary> /// /// <param name="n">The index of the test end-point to set up.</param> /// <param name="producer"><tt>true</tt> to set up a producer on the end-point.</param> /// <param name="consumer"><tt>true</tt> to set up a consumer on the end-point.</param> /// <param name="routingKey">The routing key for the producer to send on.</param> /// <param name="ackMode">The ack mode for the end-points channel.</param> /// <param name="transacted"><tt>true</tt> to use transactions on the end-points channel.</param> /// <param name="exchangeName">The exchange to produce or consume on.</param> /// <param name="declareBind"><tt>true</tt> if the consumers queue should be declared and bound, <tt>false</tt> if it has already been.</param> /// <param name="durable"><tt>true</tt> to declare the consumers queue as durable.</param> /// <param name="subscriptionName">If durable is true, the fixed unique queue name to use.</param> public void SetUpEndPoint(int n, bool producer, bool consumer, string routingKey, AcknowledgeMode ackMode, bool transacted, string exchangeName, bool declareBind, bool durable, string subscriptionName) { SetUpEndPoint(n, producer, consumer, routingKey, ackMode, transacted, exchangeName, declareBind, durable, subscriptionName, true, false); }
/// <summary> Sets up the nth test end-point. </summary> /// /// <param name="n">The index of the test end-point to set up.</param> /// <param name="producer"><tt>true</tt> to set up a producer on the end-point.</param> /// <param name="consumer"><tt>true</tt> to set up a consumer on the end-point.</param> /// <param name="routingKey">The routing key for the producer to send on.</param> /// <param name="ackMode">The ack mode for the end-points channel.</param> /// <param name="transacted"><tt>true</tt> to use transactions on the end-points channel.</param> /// <param name="exchangeName">The exchange to produce or consume on.</param> /// <param name="declareBind"><tt>true</tt> if the consumers queue should be declared and bound, <tt>false</tt> if it has already been.</param> /// <param name="durable"><tt>true</tt> to declare the consumers queue as durable.</param> /// <param name="subscriptionName">If durable is true, the fixed unique queue name to use.</param> /// <param name="exclusive"><tt>true</tt> declare queue as exclusive.</param> /// <param name="browse"><tt>true</tt> only browse, don''t consume.</param> public void SetUpEndPoint(int n, bool producer, bool consumer, string routingKey, AcknowledgeMode ackMode, bool transacted, string exchangeName, bool declareBind, bool durable, string subscriptionName, bool exclusive, bool browse) { // Allow client id to be fixed, or undefined. { // Use unique id for end point. connectionInfo = QpidConnectionInfo.FromUrl(connectionUri); connectionInfo.ClientName = "test" + n; } testConnection[n] = new AMQConnection(connectionInfo); testConnection[n].Start(); testChannel[n] = testConnection[n].CreateChannel(transacted, ackMode); if (producer) { testProducer[n] = testChannel[n].CreatePublisherBuilder() .WithExchangeName(exchangeName) .WithRoutingKey(routingKey) .Create(); } if (consumer) { string queueName; // Use the subscription name as the queue name if the subscription is durable, otherwise use a generated name. if (durable) { // The durable queue is declared without auto-delete, and passively, in case it has already been declared. queueName = subscriptionName; if (declareBind) { testChannel[n].DeclareQueue(queueName, durable, exclusive, false); testChannel[n].Bind(queueName, exchangeName, routingKey); } } else { queueName = testChannel[n].GenerateUniqueName(); if (declareBind) { if (durable) { testQueue[n] = queueName; } testChannel[n].DeclareQueue(queueName, durable, true, true); testChannel[n].Bind(queueName, exchangeName, routingKey); } } testConsumer[n] = testChannel[n].CreateConsumerBuilder(queueName).WithBrowse(browse).Create(); } }
public IChannel CreateChannel(bool transacted, AcknowledgeMode acknowledgeMode, int prefetchHigh, int prefetchLow) { CheckNotClosed(); if (ChannelLimitReached()) { throw new ChannelLimitReachedException(_maximumChannelCount); } else { CreateChannelFailoverSupport operation = new CreateChannelFailoverSupport(this, transacted, acknowledgeMode, prefetchHigh, prefetchLow); return (IChannel)operation.execute(this); } }
public AcknowledgeModeAttribute(AcknowledgeMode mode) { this.mode = mode; }
/// <summary>Determine if the acknowledge mode is transaction allowed.</summary> /// <param name="mode">The mode.</param> /// <returns>True if transaction allowed, else false.</returns> public static bool TransactionAllowed(this AcknowledgeMode mode) { return(mode == AcknowledgeMode.Auto || mode == AcknowledgeMode.Manual); }
public IChannel CreateChannel(bool transacted, AcknowledgeMode acknowledgeMode, int prefetch) { return(CreateChannel(transacted, acknowledgeMode, prefetch, prefetch)); }
public IChannel CreateChannel(bool transacted, AcknowledgeMode acknowledgeMode) { return(CreateChannel(transacted, acknowledgeMode, AmqChannel.DEFAULT_PREFETCH_HIGH_MARK)); }
public IChannel CreateChannel(bool transacted, AcknowledgeMode acknowledgeMode) { return CreateChannel(transacted, acknowledgeMode, AmqChannel.DEFAULT_PREFETCH_HIGH_MARK); }
public static RabbitMQQueueOptionsBuilder Subscribe(this RabbitMQQueueOptionsBuilder builder, AcknowledgeMode acknowledgeMode, Func <RabbitMQDelivery, Task> handler) => builder.Subscribe(acknowledgeMode, ExceptionModeAttribute.DefaultMode, handler);
public IChannel CreateChannel(bool transacted, AcknowledgeMode acknowledgeMode, int prefetch) { return CreateChannel(transacted, acknowledgeMode, prefetch, prefetch); }
public static RabbitMQQueueOptionsBuilder Subscribe(this RabbitMQQueueOptionsBuilder builder, AcknowledgeMode acknowledgeMode, ExceptionMode exceptionMode, Func <RabbitMQDelivery, Task> handler) { if (handler == null) { throw new ArgumentNullException(nameof(handler)); } builder.OnDeclaredActions.Add((services) => Task.Run(() => { var(contextAccessor, channel, queue) = services.GetContext(); var startup = services.GetService <LifecycleController>(); startup.On( LifecycleState.SubscribeQueues, () => channel.Subscribe(new QueueConsumerSubscriber(queue.Name, acknowledgeMode, exceptionMode, new LambdaMessageHandler(handler), contextAccessor)) ); })); return(builder); }
public static RabbitMQChannelOptionsBuilder AddRequestReply(this RabbitMQChannelOptionsBuilder builder, AcknowledgeMode acknowledgeMode) => builder.AddRequestReply(acknowledgeMode, ExceptionModeAttribute.DefaultMode);
public static bool IsTransactionAllowed(this AcknowledgeMode mode) { return(mode == AcknowledgeMode.AUTO || mode == AcknowledgeMode.MANUAL); }
public static RabbitMQChannelOptionsBuilder AddRequestReply(this RabbitMQChannelOptionsBuilder builder, AcknowledgeMode acknowledgeMode, ExceptionMode exceptionMode) { RequestReplyController controller = null; builder .DeclareQueue(queueBuilder => queueBuilder .OnDeclare(queue => Task.Run(() => controller = new RequestReplyController(queue.Name))) .Subscribe(acknowledgeMode, exceptionMode, delivery => controller.OnDelivery(delivery)) ) .Map <RequestReplyModel>(model => { var context = controller.Request(model.SourceContent); model.Context = context; return(context.RequestContent); }); return(builder); }
/// <summary> /// Initializes a new instance of the <see cref="AmqChannel"/> class. /// </summary> /// <param name="con">The connection.</param> /// <param name="channelId">The channel id.</param> /// <param name="transacted">if set to <c>true</c> [transacted].</param> /// <param name="acknowledgeMode">The acknowledge mode.</param> /// <param name="defaultPrefetchHigh">Default prefetch high value</param> /// <param name="defaultPrefetchLow">Default prefetch low value</param> internal AmqChannel(AMQConnection con, ushort channelId, bool transacted, AcknowledgeMode acknowledgeMode, int defaultPrefetchHigh, int defaultPrefetchLow) : this() { _sessionNumber = Interlocked.Increment(ref _nextSessionNumber); _connection = con; _transacted = transacted; if ( transacted ) { _acknowledgeMode = AcknowledgeMode.SessionTransacted; } else { _acknowledgeMode = acknowledgeMode; } _channelId = channelId; _defaultPrefetchHighMark = defaultPrefetchHigh; _defaultPrefetchLowMark = defaultPrefetchLow; if ( _acknowledgeMode == AcknowledgeMode.NoAcknowledge ) { _queue = new FlowControlQueue(_defaultPrefetchLowMark, _defaultPrefetchHighMark, new ThresholdMethod(OnPrefetchLowMark), new ThresholdMethod(OnPrefetchHighMark)); } else { // low and upper are the same _queue = new FlowControlQueue(_defaultPrefetchHighMark, _defaultPrefetchHighMark, null, null); } DefaultInstance = this; }
public static bool IsManual(this AcknowledgeMode mode) { return(mode == AcknowledgeMode.MANUAL); }
internal BasicMessageConsumer(ushort channelId, string queueName, bool noLocal, MessageFactoryRegistry messageFactory, AmqChannel channel, int prefetchHigh, int prefetchLow, bool exclusive, bool browse) { _channelId = channelId; _queueName = queueName; _noLocal = noLocal; _messageFactory = messageFactory; _channel = channel; _acknowledgeMode = _channel.AcknowledgeMode; _prefetchHigh = prefetchHigh; _prefetchLow = prefetchLow; _exclusive = exclusive; _browse = browse; if (_acknowledgeMode == AcknowledgeMode.SessionTransacted) { _receivedDeliveryTags = new LinkedList<long>(); } }