Exemple #1
0
        public async Task Should_Deliver_And_Reiieve_Messages_Serialized_With_Protobuf()
        {
            using (var client = ZyRabbitFactory.CreateTestClient(new ZyRabbitOptions {
                Plugins = p => p.UseProtobuf()
            }))
            {
                /** Setup **/
                var tcs     = new TaskCompletionSource <ProtoMessage>();
                var message = new ProtoMessage
                {
                    Member = "Straight into bytes",
                    Id     = Guid.NewGuid()
                };
                await client.SubscribeAsync <ProtoMessage>(msg =>
                {
                    tcs.TrySetResult(msg);
                    return(Task.CompletedTask);
                });

                /** Test **/
                await client.PublishAsync(message);

                await tcs.Task;

                /** Assert **/
                Assert.Equal(tcs.Task.Result.Id, message.Id);
                Assert.Equal(tcs.Task.Result.Member, message.Member);
            }
        }
Exemple #2
0
        public async Task Should_Publish_Message_To_Error_Exchange_If_Serializer_Mismatch()
        {
            using (var protobufClient = ZyRabbitFactory.CreateTestClient(new ZyRabbitOptions {
                Plugins = p => p.UseProtobuf()
            }))
                using (var jsonClient = ZyRabbitFactory.CreateTestClient())
                {
                    /** Setup **/
                    var handlerInvoked = false;
                    var tcs            = new TaskCompletionSource <ProtoMessage>();
                    var message        = new ProtoMessage
                    {
                        Member = "Straight into bytes",
                        Id     = Guid.NewGuid()
                    };
                    await jsonClient.SubscribeAsync <ProtoMessage>(msg =>
                    {
                        handlerInvoked = true;                 // Should never get here
                        return(Task.CompletedTask);
                    });

                    await protobufClient.SubscribeAsync <ProtoMessage>(msg =>
                    {
                        tcs.TrySetResult(msg);
                        return(Task.CompletedTask);
                    }, ctx => ctx.UseSubscribeConfiguration(cfg => cfg
                                                            .FromDeclaredQueue(q => q.WithName("error_queue"))
                                                            .OnDeclaredExchange(e => e.WithName("default_error_exchange"))
                                                            ));

                    /** Test **/
                    await protobufClient.PublishAsync(message);

                    await tcs.Task;

                    /** Assert **/
                    Assert.False(handlerInvoked);
                    Assert.Equal(tcs.Task.Result.Id, message.Id);
                    Assert.Equal(tcs.Task.Result.Member, message.Member);
                }
        }