|
1 | 1 | using Microsoft.AspNetCore.Mvc; |
2 | | -using Microsoft.Extensions.Logging; |
3 | | -using RabbitMQ.EventBus.AspNetCore.Attributes; |
4 | | -using RabbitMQ.EventBus.AspNetCore.Events; |
5 | 2 | using System; |
6 | | -using System.Threading.Tasks; |
7 | 3 |
|
8 | 4 | namespace RabbitMQ.EventBus.AspNetCore.Simple.Controllers |
9 | 5 | { |
10 | | - [EventBus(Exchange = "RabbitMQ.EventBus.Simple", RoutingKey = "rabbitmq.eventbus.test")] |
11 | | - public class MessageBody : IEvent |
12 | | - { |
13 | | - public string Body { get; set; } |
14 | | - public DateTimeOffset Time { get; set; } |
15 | | - } |
16 | | - //[EventBus(Exchange = "RabbitMQ.EventBus.Simple", RoutingKey = "rabbitmq.eventbus.test")] |
17 | | - [EventBus(Exchange = "RabbitMQ.EventBus.Simple", RoutingKey = "rabbitmq.eventbus.test1")] |
18 | | - public class MessageBody1 : IEvent |
19 | | - { |
20 | | - public string Body { get; set; } |
21 | | - public DateTimeOffset Time { get; set; } |
22 | | - } |
23 | | - public class MessageBodyHandle : IEventHandler<MessageBody1>, IDisposable |
24 | | - { |
25 | | - private Guid id; |
26 | | - private readonly ILogger<MessageBodyHandle> _logger; |
27 | | - |
28 | | - public MessageBodyHandle(ILogger<MessageBodyHandle> logger) |
29 | | - { |
30 | | - id = Guid.NewGuid(); |
31 | | - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); |
32 | | - } |
33 | | - public void Dispose() |
34 | | - { |
35 | | - Console.WriteLine("释放"); |
36 | | - } |
37 | | - |
38 | | - |
39 | | - public Task Handle(MessageBody1 message, EventHandlerArgs args) |
40 | | - { |
41 | | - Console.WriteLine("=================================================="); |
42 | | - Console.WriteLine(id + "=>" + typeof(MessageBody1).Name); |
43 | | - Console.WriteLine(message.Serialize()); |
44 | | - Console.WriteLine(args.Original); |
45 | | - Console.WriteLine(args.Redelivered); |
46 | | - Console.WriteLine("=================================================="); |
47 | | - return Task.CompletedTask; |
48 | | - } |
49 | | - } |
50 | 6 | [Route("api/[controller]")] |
51 | 7 | [ApiController] |
52 | 8 | public class ValuesController : ControllerBase |
|
0 commit comments