Exemple #1
0
        private static void Main(string[] args)
        {
            HmqStickyConnector connector = new HmqStickyConnector(TimeSpan.FromSeconds(2), () =>
            {
                HorseClient client = new HorseClient();
                client.SetClientType("SAMPLE-EXCEPTION-CONSUMER");
                return(client);
            });

            connector.AddHost("hmq://localhost:15500");
            connector.ContentSerializer = new NewtonsoftContentSerializer();
            connector.Observer.RegisterConsumer <SampleExceptionConsumer>();
            connector.Connected += (c) =>
            {
                Console.WriteLine("CONNECTED");
                _ = connector.GetClient().Queues.Subscribe("SAMPLE-EXCEPTION-QUEUE", false);
            };
            connector.Disconnected    += (c) => Console.WriteLine("DISCONNECTED");
            connector.MessageReceived += (client, message) => Console.WriteLine("Direct message received");
            connector.Run();

            while (true)
            {
                Console.ReadLine();
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            HmqStickyConnector connector = new HmqStickyConnector(TimeSpan.FromSeconds(2));

            connector.AddHost("hmq://localhost:26222");
            connector.ContentSerializer = new NewtonsoftContentSerializer();
            connector.Observer.RegisterConsumer <ModelAConsumer>();
            connector.Run();

            HorseConnectorBuilder builder = new HorseConnectorBuilder();


            builder.AddHost("host")
            .AddTransientConsumers(typeof(Program))
            .ConfigureModels(cfg => cfg.UseQueueName(type => type.Name)
                             .UseConsumerAck()
                             .AddMessageHeader("Sender-Client-Name", "MyName")
                             .SetPutBackDelay(TimeSpan.FromSeconds(10)));


            while (true)
            {
                Console.ReadLine();
            }
        }
Exemple #3
0
        private static async Task Main(string[] args)
        {
            HmqStickyConnector connector = new HmqStickyConnector(TimeSpan.FromSeconds(2));

            connector.AddHost("hmq://localhost:15500");
            connector.ContentSerializer = new NewtonsoftContentSerializer();
            connector.Run();

            IHorseRouteBus routeBus = connector.Bus.Route;

            while (true)
            {
                HorseResult result = await routeBus.PublishJson(new SampleMessage(), true);

                Console.WriteLine($"Push: {result.Code}");
                await Task.Delay(5000);
            }
        }
Exemple #4
0
        private static void Main(string[] args)
        {
            HmqStickyConnector connector = new HmqStickyConnector(TimeSpan.FromSeconds(2));

            connector.AddHost("hmq://localhost:15500");
            connector.ContentSerializer = new NewtonsoftContentSerializer();
            connector.Observer.RegisterConsumer <SampleMessageQueueConsumer>();
            connector.Connected += (c) =>
            {
                Console.WriteLine("CONNECTED");
                _ = connector.GetClient().Queues.Subscribe("SAMPLE-MESSAGE-QUEUE", false);
            };
            connector.Disconnected    += (c) => Console.WriteLine("DISCONNECTED");
            connector.MessageReceived += (client, message) => Console.WriteLine("Queue message received");
            connector.Run();

            while (true)
            {
                Console.ReadLine();
            }
        }
Exemple #5
0
        static void Main(string[] args)
        {
            HmqStickyConnector connector = new HmqStickyConnector(TimeSpan.FromSeconds(2), () =>
            {
                HorseClient client = new HorseClient();
                client.SetClientName("GIVE-ME-GUID-REQUEST-HANDLER-CONSUMER");
                return(client);
            });


            connector.AddHost("hmq://localhost:15500");
            connector.ContentSerializer = new NewtonsoftContentSerializer();
            connector.Observer.RegisterConsumer <GiveMeGuidRequestHandler>();
            connector.Connected       += (c) => { Console.WriteLine("CONNECTED"); };
            connector.Disconnected    += (c) => Console.WriteLine("DISCONNECTED");
            connector.MessageReceived += (client, message) => Console.WriteLine("Direct message received");
            connector.Run();

            while (true)
            {
                Console.ReadLine();
            }
        }
Exemple #6
0
        static async Task Main(string[] args)
        {
            HmqStickyConnector connector = new HmqStickyConnector(TimeSpan.FromSeconds(2));

            connector.AddHost("hmq://localhost:26222");
            connector.ContentSerializer = new NewtonsoftContentSerializer();
            connector.Run();

            IHorseQueueBus queueBus = connector.Bus.Queue;

            ModelA a = new ModelA();

            a.Foo = "foo";
            a.No  = 123;

            while (true)
            {
                HorseResult result = await queueBus.PushJson(a);

                Console.WriteLine($"Push: {result.Code}");
                await Task.Delay(5000);
            }
        }
Exemple #7
0
        private static void Main(string[] args)
        {
            HmqStickyConnector connector = new HmqStickyConnector(TimeSpan.FromSeconds(2), () =>
            {
                HorseClient client = new HorseClient();
                client.SetClientType("SAMPLE-MESSAGE-CONSUMER");
                return(client);
            });

            connector.AddHost("hmq://localhost:15500");
            connector.ContentSerializer = new NewtonsoftContentSerializer();
            connector.Observer.RegisterConsumer <SampleDirectMessageConsumer>();
            connector.Connected       += (c) => { Console.WriteLine("CONNECTED"); };
            connector.Disconnected    += (c) => Console.WriteLine("DISCONNECTED");
            connector.MessageReceived += (client, message) => Console.WriteLine("Direct message received");
            connector.Run();

            RouteBus = connector.Bus.Route;

            while (true)
            {
                Console.ReadLine();
            }
        }
Exemple #8
0
        /// <summary>
        /// Inits node options and starts the connections
        /// </summary>
        public void Initialize()
        {
            if (Server.Options.Nodes == null || Server.Options.Nodes.Length < 1)
            {
                return;
            }

            Connectors = new HmqStickyConnector[Server.Options.Nodes.Length];

            for (int i = 0; i < Connectors.Length; i++)
            {
                NodeOptions options   = Server.Options.Nodes[i];
                TimeSpan    reconnect = TimeSpan.FromMilliseconds(options.ReconnectWait);

                HmqStickyConnector connector = options.KeepMessages
                                                   ? new HmqAbsoluteConnector(reconnect, () => CreateInstanceClient(options))
                                                   : new HmqStickyConnector(reconnect, () => CreateInstanceClient(options));

                Connectors[i] = connector;
                connector.Tag = options;

                connector.AddHost(options.Host);
            }
        }