mirror of https://github.com/dotnet/tye.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.3 KiB
42 lines
1.3 KiB
// Licensed to the .NET Foundation under one or more agreements.
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Logging;
|
|
using RabbitMQ.Client;
|
|
using Shared;
|
|
|
|
namespace Backend
|
|
{
|
|
public class OrdersService : IOrderService
|
|
{
|
|
private readonly ILogger<OrdersService> _logger;
|
|
private readonly IModel _client;
|
|
|
|
public OrdersService(ILogger<OrdersService> logger, IModel client)
|
|
{
|
|
_logger = logger;
|
|
_client = client;
|
|
}
|
|
|
|
public ValueTask PlaceOrderAsync(Order order)
|
|
{
|
|
var orderBytes = JsonSerializer.SerializeToUtf8Bytes(order);
|
|
|
|
// Use the raw log API to avoid formatting the JSON string (since it has {})
|
|
var text = Encoding.UTF8.GetString(orderBytes);
|
|
_logger.Log(LogLevel.Information, 0, "Recieved: " + text, exception: null, formatter: (m, e) => m);
|
|
|
|
_client.BasicPublish(
|
|
exchange: "",
|
|
routingKey: "orders",
|
|
basicProperties: null,
|
|
body: orderBytes);
|
|
|
|
return default;
|
|
}
|
|
}
|
|
}
|
|
|