Skip to content

Commit 614501e

Browse files
authored
Merge pull request #29 from ojdev/dev
Dev
2 parents f871f1d + efc0b36 commit 614501e

8 files changed

Lines changed: 66 additions & 55 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# RabbitMQ.EventBus.AspNetCore           [Wiki](https://github.com/ojdev/RabbitMQ.EventBus.AspNetCore/wiki)
2-
[![DNC](https://img.shields.io/badge/.netcore-%3E%3D2.0-green.svg)](#)
2+
[![DNC](https://img.shields.io/badge/.netcore-%3E%3D2.1-green.svg)](#)
3+
[![CodeFactor](https://www.codefactor.io/repository/github/ojdev/rabbitmq.eventbus.aspnetcore/badge)](https://www.codefactor.io/repository/github/ojdev/rabbitmq.eventbus.aspnetcore)
34
[![AppVeyor](https://img.shields.io/appveyor/ci/ojdev/rabbitmq-eventbus-aspnetcore.svg?style=popout)](https://ci.appveyor.com/project/ojdev/rabbitmq-eventbus-aspnetcore)
45
[![NuGet](https://img.shields.io/nuget/v/RabbitMQ.EventBus.AspNetCore.svg?style=popout)](https://www.nuget.org/packages/RabbitMQ.EventBus.AspNetCore)
56
[![NuGet](https://img.shields.io/nuget/dt/RabbitMQ.EventBus.AspNetCore.svg?style=popout)](https://www.nuget.org/packages/RabbitMQ.EventBus.AspNetCore)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using RabbitMQ.EventBus.AspNetCore.Attributes;
2+
using RabbitMQ.EventBus.AspNetCore.Events;
3+
using System;
4+
5+
namespace RabbitMQ.EventBus.AspNetCore.Simple.Controllers
6+
{
7+
[EventBus(Exchange = "RabbitMQ.EventBus.Simple", RoutingKey = "rabbitmq.eventbus.test")]
8+
public class MessageBody : IEvent
9+
{
10+
public string Body { get; set; }
11+
public DateTimeOffset Time { get; set; }
12+
}
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using RabbitMQ.EventBus.AspNetCore.Attributes;
2+
using RabbitMQ.EventBus.AspNetCore.Events;
3+
using System;
4+
5+
namespace RabbitMQ.EventBus.AspNetCore.Simple.Controllers
6+
{
7+
//[EventBus(Exchange = "RabbitMQ.EventBus.Simple", RoutingKey = "rabbitmq.eventbus.test")]
8+
[EventBus(Exchange = "RabbitMQ.EventBus.Simple", RoutingKey = "rabbitmq.eventbus.test1")]
9+
public class MessageBody1 : IEvent
10+
{
11+
public string Body { get; set; }
12+
public DateTimeOffset Time { get; set; }
13+
}
14+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Microsoft.Extensions.Logging;
2+
using RabbitMQ.EventBus.AspNetCore.Events;
3+
using System;
4+
using System.Threading.Tasks;
5+
6+
namespace RabbitMQ.EventBus.AspNetCore.Simple.Controllers
7+
{
8+
public class MessageBodyHandle : IEventHandler<MessageBody1>, IDisposable
9+
{
10+
private Guid id;
11+
private readonly ILogger<MessageBodyHandle> _logger;
12+
13+
public MessageBodyHandle(ILogger<MessageBodyHandle> logger)
14+
{
15+
id = Guid.NewGuid();
16+
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
17+
}
18+
public void Dispose()
19+
{
20+
Console.WriteLine("释放");
21+
}
22+
23+
public Task Handle(MessageBody1 message, EventHandlerArgs args)
24+
{
25+
Console.WriteLine("==================================================");
26+
Console.WriteLine(id + "=>" + typeof(MessageBody1).Name);
27+
Console.WriteLine(message.Serialize());
28+
Console.WriteLine(args.Original);
29+
Console.WriteLine(args.Redelivered);
30+
Console.WriteLine("==================================================");
31+
return Task.CompletedTask;
32+
}
33+
}
34+
}

RabbitMQ.EventBus.AspNetCore.Simple/Controllers/ValuesController.cs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,8 @@
11
using Microsoft.AspNetCore.Mvc;
2-
using Microsoft.Extensions.Logging;
3-
using RabbitMQ.EventBus.AspNetCore.Attributes;
4-
using RabbitMQ.EventBus.AspNetCore.Events;
52
using System;
6-
using System.Threading.Tasks;
73

84
namespace RabbitMQ.EventBus.AspNetCore.Simple.Controllers
95
{
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-
}
506
[Route("api/[controller]")]
517
[ApiController]
528
public class ValuesController : ControllerBase

src/RabbitMQ.EventBus.AspNetCore/Events/IEvent.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ namespace RabbitMQ.EventBus.AspNetCore.Events
77
/// </summary>
88
public interface IEvent
99
{
10-
1110
}
12-
}
11+
}

src/RabbitMQ.EventBus.AspNetCore/Factories/DefaultRabbitMQPersistentConnection.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace RabbitMQ.EventBus.AspNetCore.Factories
1313
{
14-
1514
internal sealed class DefaultRabbitMQPersistentConnection : IRabbitMQPersistentConnection
1615
{
1716
public RabbitMQEventBusConnectionConfiguration Configuration { get; }
@@ -21,7 +20,6 @@ internal sealed class DefaultRabbitMQPersistentConnection : IRabbitMQPersistentC
2120
private bool _disposed;
2221
private readonly object sync_root = new object();
2322

24-
2523
public string Endpoint => _connection?.Endpoint.ToString();
2624
public DefaultRabbitMQPersistentConnection(RabbitMQEventBusConnectionConfiguration configuration, IConnectionFactory connectionFactory, ILogger<DefaultRabbitMQPersistentConnection> logger)
2725
{
@@ -32,18 +30,15 @@ public DefaultRabbitMQPersistentConnection(RabbitMQEventBusConnectionConfigurati
3230

3331
public bool IsConnected => _connection != null && _connection.IsOpen && !_disposed;
3432

35-
3633
public IModel CreateModel()
3734
{
3835
if (!IsConnected)
3936
{
4037
throw new InvalidOperationException("No RabbitMQ connections are available to perform this action");
4138
}
42-
4339
return _connection.CreateModel();
4440
}
4541

46-
4742
public void Dispose()
4843
{
4944
if (_disposed)
@@ -61,7 +56,6 @@ public void Dispose()
6156
}
6257
}
6358

64-
6559
public bool TryConnect()
6660
{
6761
_logger.WriteLog(Configuration.Level, "RabbitMQ Client is trying to connect");
@@ -96,6 +90,7 @@ public bool TryConnect()
9690
}
9791
}
9892
}
93+
9994
private void OnConnectionBlocked(object sender, ConnectionBlockedEventArgs e)
10095
{
10196
if (_disposed)

src/RabbitMQ.EventBus.AspNetCore/Factories/IRabbitMQPersistentConnection.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ public interface IRabbitMQPersistentConnection : IDisposable
3131
/// </summary>
3232
/// <returns></returns>
3333
IModel CreateModel();
34-
3534
}
36-
}
35+
}

0 commit comments

Comments
 (0)