Exemplo n.º 1
0
        public void Set_routing_key_per_message_and_consume_them_in_the_same_process()
        {
            string GetRoutingKey(string s) => $"key.{s}";

            var exchangeName        = "amqp.topic." + Environment.TickCount;
            var queueName           = "amqp-conn-it-spec-simple-queue-" + Environment.TickCount;
            var exchangeDeclaration = ExchangeDeclaration.Create(exchangeName, "topic");
            var queueDeclaration    = QueueDeclaration.Create(queueName);
            var bindingDeclaration  = BindingDeclaration.Create(queueName, exchangeName).WithRoutingKey(GetRoutingKey("*"));

            var amqpSink = AmqpSink.Create(
                AmqpSinkSettings.Create(_connectionSettings)
                .WithExchange(exchangeName)
                .WithDeclarations(exchangeDeclaration, queueDeclaration, bindingDeclaration));

            var amqpSource = AmqpSource.AtMostOnceSource(
                NamedQueueSourceSettings.Create(_connectionSettings, queueName).WithDeclarations(exchangeDeclaration, queueDeclaration, bindingDeclaration),
                bufferSize: 10);

            var input       = new[] { "one", "two", "three", "four", "five" };
            var routingKeys = input.Select(GetRoutingKey);

            Source.From(input)
            .Select(s => new OutgoingMessage(ByteString.FromString(s), false, false, routingKey: GetRoutingKey(s)))
            .RunWith(amqpSink, _mat)
            .Wait();

            var result = amqpSource
                         .Take(input.Length)
                         .RunWith(Sink.Seq <IncomingMessage>(), _mat)
                         .Result;

            result.Select(x => x.Envelope.RoutingKey).Should().Equal(routingKeys);
            result.Select(x => x.Bytes.ToString()).Should().Equal(input);
        }
Exemplo n.º 2
0
        public async Task Publish_and_consume_elements_through_a_simple_queue_again_in_the_same_process()
        {
            Connection.DisableServerCertValidation = true;
            Trace.TraceLevel    = TraceLevel.Frame;
            Trace.TraceListener = (l, f, a) =>
                                  Output.WriteLine(DateTime.Now.ToString("[hh:mm:ss.fff]") + " " + string.Format(f, a));

            var connection = new Connection(_address);
            var session    = new Session(connection);

            var queueName        = "simple-v1-queue-test" + Guid.NewGuid();
            var senderLinkName   = "amqp-v1-conn-test-sender";
            var receiverLinkName = "amqp-v1-conn-test-receiver";

            //create sink and source
            var amqpSink   = AmqpSink.Create(new NamedQueueSinkSettings <string>(session, senderLinkName, queueName, _serializer));
            var amqpSource = AmqpSource.Create(new NamedQueueSourceSettings <string>(session, receiverLinkName, queueName, 200, _serializer));

            //run sink
            var input = new[] { "one", "two", "three", "four", "five" };
            await Source.From(input).RunWith(amqpSink, _materializer);

            //run source
            var result = amqpSource
                         .Take(input.Length)
                         .RunWith(Sink.Seq <string>(), _materializer);

            await result;

            Assert.True(result.IsCompleted);
            Assert.Equal(input, result.Result);

            await session.CloseAsync();

            await connection.CloseAsync();
        }