Esempio n. 1
0
        public async Task <string> SendHttpRequestAsync(IMessage message)
        {
            using (var tokenScope = cancelationTokenStore.CreateScope(message.MessageId))
            {
                var httpClient = clientFactory.CreateClient();
                var request    = new HttpRequestMessage(HttpMethod.Get, "http://localhost:7071/api/Function1");

                var response = await httpClient.SendAsync(request, tokenScope.Token);

                if (response.IsSuccessStatusCode)
                {
                    return(await response.Content.ReadAsStringAsync());
                }
                return(null);
            }
        }
Esempio n. 2
0
        public async Task Consume(ConsumeContext <MessageSubmit> context)
        {
            using (var tokenScope = cancelationTokenStore.CreateScope(context.Message.MessageId))
            {
                var httpClient = clientFactory.CreateClient();
                var request    = new HttpRequestMessage(HttpMethod.Get, "http://localhost:7071/api/Function1");

                var response = await httpClient.SendAsync(request, tokenScope.Token);

                if (response.IsSuccessStatusCode)
                {
                    var result = await response.Content.ReadAsStringAsync();

                    logger.LogInformation(result);
                    await hubContext.Clients.All.SendAsync("broadcastMessage", "MessagesConsumer", result);

                    await publishEndpoint.Publish(new MessageProcessed(context.Message.MessageId, DateTime.Now), tokenScope.Token);
                }
                else
                {
                    await publishEndpoint.Publish(new MessageError(context.Message.MessageId, DateTime.Now), tokenScope.Token);
                }
            }
        }