Ejemplo n.º 1
0
        public void Start()
        {
            _connector.AddHost("tmq://localhost:48050");

            _connector.Connected       += Connected;
            _connector.MessageReceived += MessageReceived;
            _connector.Run();

            _timer = new Timer(async o =>
            {
                if (_connector.IsConnected)
                {
                    TmqClient client = _connector.GetClient();

                    TmqMessage message  = new TmqMessage(MessageType.Client, "producer-id");
                    message.ContentType = ModelTypes.ConsumerRequest;

                    ConsumerRequest request = new ConsumerRequest();
                    request.Guid            = Guid.NewGuid().ToString();

                    await message.SetJsonContent(request);
                    TmqMessage response     = await client.Request(message);
                    ProducerResponse rmodel = await response.GetJsonContent <ProducerResponse>();
                    Console.WriteLine($"> response received for: {rmodel.RequestGuid}");
                }
            }, null, 6000, 6000);
        }
Ejemplo n.º 2
0
        private void MessageReceived(ClientSocketBase <TmqMessage> client, TmqMessage message)
        {
            switch (message.Type)
            {
            case MessageType.Channel:
                if (message.ContentType == ModelTypes.ProducerEvent)
                {
                    ProducerEvent e = message.GetJsonContent <ProducerEvent>().Result;
                    Console.WriteLine(message.Target == "AckChannel"
                                              ? $"> AckChannel received: #{e.No}"
                                              : $"> BasicChannel received: #{e.No}");
                }

                break;
            }
        }
Ejemplo n.º 3
0
        private void MessageReceived(ClientSocketBase <TmqMessage> client, TmqMessage message)
        {
            if (message.Type == MessageType.Client && message.ContentType == ModelTypes.ConsumerRequest)
            {
                ConsumerRequest request = message.GetJsonContent <ConsumerRequest>().Result;
                Console.WriteLine($"Consumer request received: {request.Guid}");

                ProducerResponse model = new ProducerResponse();
                model.RequestGuid  = request.Guid;
                model.ResponseGuid = Guid.NewGuid().ToString();

                TmqMessage response = message.CreateResponse();
                response.ContentType = ModelTypes.ProducerResponse;
                response.SetJsonContent(model);
                TmqClient tmq = (TmqClient)client;
                tmq.Send(response);
            }
        }