Commit a0a824f2 by AlexNasyr

IProduser instead of IAnonimusProducer

parent d0282047
...@@ -5,17 +5,15 @@ using System.Threading.Tasks; ...@@ -5,17 +5,15 @@ using System.Threading.Tasks;
namespace DDO_Application.Model { namespace DDO_Application.Model {
public class MessageProducer { public class MessageProducer {
private readonly IAnonymousProducer _producer; private readonly IProducer _producer;
private string _address;
public MessageProducer(IAnonymousProducer producer, IConfiguration configuration) { public MessageProducer(IProducer producer) {
_producer = producer; _producer = producer;
_address = configuration.GetSection("TestQueues").Get<configTestQueues>().Out;
} }
public async Task PublishAsync<T>(T message) { public async Task PublishAsync<T>(T message) {
var serialized = JsonSerializer.Serialize(message); var serialized = JsonSerializer.Serialize(message);
var msg = new Message(serialized); var msg = new Message(serialized);
await _producer.SendAsync(_address, msg); await _producer.SendAsync(msg);
} }
} }
} }
\ No newline at end of file
...@@ -22,17 +22,18 @@ namespace DDO_Application { ...@@ -22,17 +22,18 @@ namespace DDO_Application {
public void ConfigureServices(IServiceCollection services) { public void ConfigureServices(IServiceCollection services) {
var ActiveMQ = Configuration.GetSection("ActiveMQ").Get<configActiveMQ>().Endpoint; var ActiveMQ = Configuration.GetSection("ActiveMQ").Get<configActiveMQ>().Endpoint;
var msgQueues = Configuration.GetSection("TestQueues").Get<configTestQueues>();
services.AddControllers(); services.AddControllers();
services.AddSwaggerGen(c => {c.SwaggerDoc("v1", new OpenApiInfo { Title = "DDO_Application", Version = "v1" }); }); services.AddSwaggerGen(c => {c.SwaggerDoc("v1", new OpenApiInfo { Title = "DDO_Application", Version = "v1" }); });
services.AddHostedService<ApiHostedService>(); services.AddHostedService<ApiHostedService>();
services.AddSingleton<IApiService, ApiProcessingService>(); services.AddSingleton<IApiService, ApiProcessingService>();
// turn enable ActiveMQ support in project // turn enable ActiveMQ support in project
services.AddActiveMq("ddoApp-cluster", new[] { Endpoint.Create(host: "172.17.100.121", port: 61616, "contingent", "RjQ66VWS") }) //services.AddActiveMq("ddoApp-cluster", new[] { Endpoint.Create(host: "172.17.100.121", port: 61616, "contingent", "RjQ66VWS") })
//services.AddActiveMq("ddoApp-cluster", new[] { Endpoint.Create(host: "192.168.2.19", port: 5672, "guest", "guest") }) services.AddActiveMq("ddoApp-cluster", new[] { Endpoint.Create(host: "192.168.2.19", port: 5672, "guest", "guest") })
//services.AddActiveMq("ddoApp-cluster", new[] { ActiveMQ }) //services.AddActiveMq("ddoApp-cluster", new[] { ActiveMQ })
.AddAnonymousProducer<MessageProducer>() .AddProducer<MessageProducer>(msgQueues.Out)
.AddTypedConsumer<TestMessage, MessageCunsomer>(Configuration.GetSection("TestQueues").Get<configTestQueues>().In, RoutingType.Multicast); .AddTypedConsumer<TestMessage, MessageCunsomer>(msgQueues.In, RoutingType.Multicast);
services.AddActiveMqHostedService(); services.AddActiveMqHostedService();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment