Esempio n. 1
0
        private async void MessageReceived(object model, BasicDeliverEventArgs ea, IModel channel)
        {
            var inboundMessage    = ea.Body;
            var inboundProperties = ea.BasicProperties;

            var responseProperties = channel.CreateBasicProperties();

            responseProperties.CorrelationId = inboundProperties.CorrelationId;
            responseProperties.ReplyTo       = inboundProperties.ReplyTo;

            var             message      = Encoding.UTF8.GetString(inboundMessage.ToArray());
            GetSpaceRequest spaceRequest = JsonConvert.DeserializeObject <GetSpaceRequest>(message);

            logger.LogInformation("Space with guid '{spaceGuid}' is received: ", spaceRequest.SpaceGuid);

            var spaceResponse = await spacesService.GetAsync(spaceRequest.SpaceGuid);

            byte[] responseBytes =
                Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(
                                           autoMapper.Map <Response <GetSpaceResponse> >(spaceResponse)));
            string routingKey = ResponseBindingKeys[0];

            channel.BasicPublish(exchange: ResponseExchange,
                                 routingKey: routingKey,
                                 basicProperties: responseProperties,
                                 body: responseBytes);

            channel.BasicAck(deliveryTag: ea.DeliveryTag,
                             multiple: false);
            logger.LogInformation("Response is sent via '{routingKey}' BindingKey", routingKey);
        }
Esempio n. 2
0
        public Task <Response <GetSpaceResponse> > GetSpaceAsync(GetSpaceRequest request)
        {
            Console.WriteLine("Request for Workplaces is sent");
            var item = Message(request);

            return(Task.FromResult(item));
        }
Esempio n. 3
0
        private Response <GetSpaceResponse> Message(GetSpaceRequest Request)
        {
            var message      = JsonConvert.SerializeObject(Request);
            var messageBytes = Encoding.UTF8.GetBytes(message);

            channel.BasicPublish(
                exchange: RequestExchange,
                routingKey: RequestBindingKey,
                basicProperties: properties,
                body: messageBytes);

            channel.BasicConsume(
                consumer: consumer,
                queue: ResponseQueueName,
                autoAck: true);
            var item = Responses.Take();

            return(item);
        }