Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #29

Merged
merged 2 commits into from
Feb 18, 2019
Merged

Dev #29

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# RabbitMQ.EventBus.AspNetCore           [Wiki](https://github.com/ojdev/RabbitMQ.EventBus.AspNetCore/wiki)
[![DNC](https://img.shields.io/badge/.netcore-%3E%3D2.0-green.svg)](#)
[![DNC](https://img.shields.io/badge/.netcore-%3E%3D2.1-green.svg)](#)
[![CodeFactor](https://www.codefactor.io/repository/github/ojdev/rabbitmq.eventbus.aspnetcore/badge)](https://www.codefactor.io/repository/github/ojdev/rabbitmq.eventbus.aspnetcore)
[![AppVeyor](https://img.shields.io/appveyor/ci/ojdev/rabbitmq-eventbus-aspnetcore.svg?style=popout)](https://ci.appveyor.com/project/ojdev/rabbitmq-eventbus-aspnetcore)
[![NuGet](https://img.shields.io/nuget/v/RabbitMQ.EventBus.AspNetCore.svg?style=popout)](https://www.nuget.org/packages/RabbitMQ.EventBus.AspNetCore)
[![NuGet](https://img.shields.io/nuget/dt/RabbitMQ.EventBus.AspNetCore.svg?style=popout)](https://www.nuget.org/packages/RabbitMQ.EventBus.AspNetCore)
Expand Down
13 changes: 13 additions & 0 deletions RabbitMQ.EventBus.AspNetCore.Simple/Controllers/MessageBody.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using RabbitMQ.EventBus.AspNetCore.Attributes;
using RabbitMQ.EventBus.AspNetCore.Events;
using System;

namespace RabbitMQ.EventBus.AspNetCore.Simple.Controllers
{
[EventBus(Exchange = "RabbitMQ.EventBus.Simple", RoutingKey = "rabbitmq.eventbus.test")]
public class MessageBody : IEvent
{
public string Body { get; set; }
public DateTimeOffset Time { get; set; }
}
}
14 changes: 14 additions & 0 deletions RabbitMQ.EventBus.AspNetCore.Simple/Controllers/MessageBody1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using RabbitMQ.EventBus.AspNetCore.Attributes;
using RabbitMQ.EventBus.AspNetCore.Events;
using System;

namespace RabbitMQ.EventBus.AspNetCore.Simple.Controllers
{
//[EventBus(Exchange = "RabbitMQ.EventBus.Simple", RoutingKey = "rabbitmq.eventbus.test")]
[EventBus(Exchange = "RabbitMQ.EventBus.Simple", RoutingKey = "rabbitmq.eventbus.test1")]
public class MessageBody1 : IEvent
{
public string Body { get; set; }
public DateTimeOffset Time { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.Extensions.Logging;
using RabbitMQ.EventBus.AspNetCore.Events;
using System;
using System.Threading.Tasks;

namespace RabbitMQ.EventBus.AspNetCore.Simple.Controllers
{
public class MessageBodyHandle : IEventHandler<MessageBody1>, IDisposable
{
private Guid id;
private readonly ILogger<MessageBodyHandle> _logger;

public MessageBodyHandle(ILogger<MessageBodyHandle> logger)
{
id = Guid.NewGuid();
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public void Dispose()
{
Console.WriteLine("释放");
}

public Task Handle(MessageBody1 message, EventHandlerArgs args)
{
Console.WriteLine("==================================================");
Console.WriteLine(id + "=>" + typeof(MessageBody1).Name);
Console.WriteLine(message.Serialize());
Console.WriteLine(args.Original);
Console.WriteLine(args.Redelivered);
Console.WriteLine("==================================================");
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,52 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using RabbitMQ.EventBus.AspNetCore.Attributes;
using RabbitMQ.EventBus.AspNetCore.Events;
using System;
using System.Threading.Tasks;

namespace RabbitMQ.EventBus.AspNetCore.Simple.Controllers
{
[EventBus(Exchange = "RabbitMQ.EventBus.Simple", RoutingKey = "rabbitmq.eventbus.test")]
public class MessageBody : IEvent
{
public string Body { get; set; }
public DateTimeOffset Time { get; set; }
}
//[EventBus(Exchange = "RabbitMQ.EventBus.Simple", RoutingKey = "rabbitmq.eventbus.test")]
[EventBus(Exchange = "RabbitMQ.EventBus.Simple", RoutingKey = "rabbitmq.eventbus.test1")]
public class MessageBody1 : IEvent
{
public string Body { get; set; }
public DateTimeOffset Time { get; set; }
}
public class MessageBodyHandle : IEventHandler<MessageBody1>, IDisposable
{
private Guid id;
private readonly ILogger<MessageBodyHandle> _logger;

public MessageBodyHandle(ILogger<MessageBodyHandle> logger)
{
id = Guid.NewGuid();
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public void Dispose()
{
Console.WriteLine("释放");
}


public Task Handle(MessageBody1 message, EventHandlerArgs args)
{
Console.WriteLine("==================================================");
Console.WriteLine(id + "=>" + typeof(MessageBody1).Name);
Console.WriteLine(message.Serialize());
Console.WriteLine(args.Original);
Console.WriteLine(args.Redelivered);
Console.WriteLine("==================================================");
return Task.CompletedTask;
}
}
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
Expand Down
3 changes: 1 addition & 2 deletions src/RabbitMQ.EventBus.AspNetCore/Events/IEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ namespace RabbitMQ.EventBus.AspNetCore.Events
/// </summary>
public interface IEvent
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace RabbitMQ.EventBus.AspNetCore.Factories
{

internal sealed class DefaultRabbitMQPersistentConnection : IRabbitMQPersistentConnection
{
public RabbitMQEventBusConnectionConfiguration Configuration { get; }
Expand All @@ -21,7 +20,6 @@ internal sealed class DefaultRabbitMQPersistentConnection : IRabbitMQPersistentC
private bool _disposed;
private readonly object sync_root = new object();


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

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


public IModel CreateModel()
{
if (!IsConnected)
{
throw new InvalidOperationException("No RabbitMQ connections are available to perform this action");
}

return _connection.CreateModel();
}


public void Dispose()
{
if (_disposed)
Expand All @@ -61,7 +56,6 @@ public void Dispose()
}
}


public bool TryConnect()
{
_logger.WriteLog(Configuration.Level, "RabbitMQ Client is trying to connect");
Expand Down Expand Up @@ -96,6 +90,7 @@ public bool TryConnect()
}
}
}

private void OnConnectionBlocked(object sender, ConnectionBlockedEventArgs e)
{
if (_disposed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ public interface IRabbitMQPersistentConnection : IDisposable
/// </summary>
/// <returns></returns>
IModel CreateModel();

}
}
}