Exemple #1
0
        /// <summary>
        /// The configure bus.
        /// </summary>
        /// <param name="cfg">
        /// The cfg.
        /// </param>
        private static void ConfigureBus(IBusConfigurator cfg)
        {
            cfg.UseRabbitMq();
            cfg.SetEndpoint(Params.Endpoint);
            cfg.SetConnectionString(Params.ConnectionString);
            cfg.UseParallelismLevel(Params.ParallelismLevel);

            ISenderConfigurator routeCfg = cfg.Route(Params.Type).
                WithDefaultCallbackEndpoint().
                Persistently();
            if (Params.RequireConfirmation)
            {
                routeCfg.WithConfirmation();
            }

            routeCfg = cfg.Route("bad.msg").
                WithDefaultCallbackEndpoint();
            if (Params.RequireConfirmation)
            {
                routeCfg.WithConfirmation();
            }
        }
Exemple #2
0
        /// <summary>
        /// The configure bus.
        /// </summary>
        /// <param name="cfg">
        /// The cfg.
        /// </param>
        private static void ConfigureBus(IBusConfigurator cfg)
        {
            cfg.UseRabbitMq();
            cfg.SetEndpoint(Params.Endpoint);
            cfg.SetConnectionString(Params.ConnectionString);
            cfg.UseParallelismLevel(Params.ParallelismLevel);

            ISenderConfigurator routeCfg = cfg.Route(Params.Type).
                                           WithDefaultCallbackEndpoint().
                                           Persistently();

            if (Params.RequireConfirmation)
            {
                routeCfg.WithConfirmation();
            }

            routeCfg = cfg.Route("bad.msg").
                       WithDefaultCallbackEndpoint();
            if (Params.RequireConfirmation)
            {
                routeCfg.WithConfirmation();
            }
        }
Exemple #3
0
        /// <summary>
        /// The configure bus.
        /// </summary>
        /// <param name="cfg">
        /// The cfg.
        /// </param>
        /// <exception cref="AccessViolationException">
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// </exception>
        private static void ConfigureBus(IBusConfigurator cfg)
        {
            cfg.UseRabbitMq();
            cfg.SetEndpoint(Params.Endpoint);
            cfg.SetConnectionString(Params.ConnectionString);
            cfg.UseParallelismLevel(Params.ParallelismLevel);

            IReceiverConfigurator subscriberCfg = cfg.On(Params.Type);
            if (Params.RequireAccept)
            {
                subscriberCfg.RequiresAccept();
            }

            switch (Params.Type)
            {
                case ConsumerParams.OneWay:
                    subscriberCfg.ReactWith<OneWay>(
                        (m, ctx) =>
                            {
                                Console.WriteLine("Received {0} with label [{1}].", m.Number, ctx.Message.Label);

                                Thread.Sleep((int)Params.ConsumingDelay);

                                if (Params.Misbehave)
                                {
                                    if (Random.Next(10) == 0)
                                    {
                                        throw new AccessViolationException("un oh...");
                                    }
                                }

                                ctx.Accept();
                            });
                    break;
                case ConsumerParams.Request:

                    /*
                    subscriberCfg.ReactWith<WrongRequest>((m, ctx) =>
                    {
                        Console.WriteLine("Received {0}. Sending response...", m.Number);
                        ctx.Reply(new Response(666));
                        ctx.Accept();
                    });
            */
                    subscriberCfg.ReactWith<Request>(
                        (m, ctx) =>
                            {
                                Console.WriteLine("Received {0}. Sending response...", m.Number);

                                if (Params.Misbehave)
                                {
                                    if (Random.Next(10) == 0)
                                    {
                                        throw new AccessViolationException("un oh...");
                                    }
                                }

                                // Thread.Sleep(50000);
                                ctx.Reply(new Response(m.Number));
                                ctx.Accept();
                            });
                    break;
                default:
                    throw new NotSupportedException("Unknown consumer type: " + Params.Type);
            }
        }
Exemple #4
0
        /// <summary>
        /// The configure bus.
        /// </summary>
        /// <param name="cfg">
        /// The cfg.
        /// </param>
        /// <exception cref="AccessViolationException">
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// </exception>
        private static void ConfigureBus(IBusConfigurator cfg)
        {
            cfg.UseRabbitMq();
            cfg.SetEndpoint(Params.Endpoint);
            cfg.SetConnectionString(Params.ConnectionString);
            cfg.UseParallelismLevel(Params.ParallelismLevel);

            IReceiverConfigurator subscriberCfg = cfg.On(Params.Type);

            if (Params.RequireAccept)
            {
                subscriberCfg.RequiresAccept();
            }

            switch (Params.Type)
            {
            case ConsumerParams.OneWay:
                subscriberCfg.ReactWith <OneWay>(
                    (m, ctx) =>
                {
                    Console.WriteLine("Received {0} with label [{1}].", m.Number, ctx.Message.Label);

                    Thread.Sleep((int)Params.ConsumingDelay);

                    if (Params.Misbehave)
                    {
                        if (Random.Next(10) == 0)
                        {
                            throw new AccessViolationException("un oh...");
                        }
                    }

                    ctx.Accept();
                });
                break;

            case ConsumerParams.Request:

                /*
                 *                  subscriberCfg.ReactWith<WrongRequest>((m, ctx) =>
                 *                  {
                 *                          Console.WriteLine("Received {0}. Sending response...", m.Number);
                 *                          ctx.Reply(new Response(666));
                 *                          ctx.Accept();
                 *                  });
                 */
                subscriberCfg.ReactWith <Request>(
                    (m, ctx) =>
                {
                    Console.WriteLine("Received {0}. Sending response...", m.Number);

                    if (Params.Misbehave)
                    {
                        if (Random.Next(10) == 0)
                        {
                            throw new AccessViolationException("un oh...");
                        }
                    }

                    // Thread.Sleep(50000);
                    ctx.Reply(new Response(m.Number));
                    ctx.Accept();
                });
                break;

            default:
                throw new NotSupportedException("Unknown consumer type: " + Params.Type);
            }
        }