diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo.Abp.EventBus.RabbitMQ.csproj b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo.Abp.EventBus.RabbitMQ.csproj
index 04d57417e1..c9bab15898 100644
--- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo.Abp.EventBus.RabbitMQ.csproj
+++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo.Abp.EventBus.RabbitMQ.csproj
@@ -4,8 +4,8 @@
netstandard2.0
- Volo.Abp.EventBus.Distributed.RabbitMQ
- Volo.Abp.EventBus.Distributed.RabbitMQ
+ Volo.Abp.EventBus.RabbitMQ
+ Volo.Abp.EventBus.RabbitMQ
$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;
false
false
diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs
index 4de808defa..223ea4225f 100644
--- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs
+++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs
@@ -38,7 +38,7 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq
IHybridServiceScopeFactory serviceScopeFactory,
IOptions distributedEventBusOptions,
IRabbitMqMessageConsumerFactory messageConsumerFactory)
- : base(serviceScopeFactory)
+ : base(serviceScopeFactory)
{
ConnectionPool = connectionPool;
Serializer = serializer;
@@ -52,7 +52,8 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq
Consumer = MessageConsumerFactory.Create(
new ExchangeDeclareConfiguration(
RabbitMqDistributedEventBusOptions.ExchangeName,
- type: "direct"
+ type: "direct",
+ durable: true
),
new QueueDeclareConfiguration(
RabbitMqDistributedEventBusOptions.ClientName,
@@ -96,7 +97,6 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq
if (handlerFactories.Count == 1) //TODO: Multi-threading!
{
var eventName = EventNameAttribute.GetNameOrDefault(eventType);
-
Consumer.BindAsync(eventName);
}
@@ -166,8 +166,8 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq
{
channel.ExchangeDeclare(
RabbitMqDistributedEventBusOptions.ExchangeName,
- "direct"
- //TODO: Other properties like durable?
+ "direct",
+ durable: true
);
var properties = channel.CreateBasicProperties();
diff --git a/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumer.cs b/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumer.cs
index a41054a45f..a56fc2491a 100644
--- a/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumer.cs
+++ b/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumer.cs
@@ -145,7 +145,10 @@ namespace Volo.Abp.RabbitMQ
channel.ExchangeDeclare(
exchange: Exchange.ExchangeName,
- type: Exchange.Type
+ type: Exchange.Type,
+ durable: Exchange.Durable,
+ autoDelete: Exchange.AutoDelete,
+ arguments: Exchange.Arguments
);
channel.QueueDeclare(
@@ -212,6 +215,7 @@ namespace Volo.Abp.RabbitMQ
public virtual void Dispose()
{
+ Timer.Stop();
DisposeChannel();
}
diff --git a/samples/RabbitMqEventBus/App1/App1.csproj b/samples/RabbitMqEventBus/App1/App1.csproj
index 1d59d978ec..7bc8ca1c21 100644
--- a/samples/RabbitMqEventBus/App1/App1.csproj
+++ b/samples/RabbitMqEventBus/App1/App1.csproj
@@ -6,6 +6,7 @@
+
diff --git a/samples/RabbitMqEventBus/App1/App1MessagingService.cs b/samples/RabbitMqEventBus/App1/App1MessagingService.cs
index 718a0b76de..89f2bab336 100644
--- a/samples/RabbitMqEventBus/App1/App1MessagingService.cs
+++ b/samples/RabbitMqEventBus/App1/App1MessagingService.cs
@@ -4,7 +4,7 @@ using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus;
using Volo.Abp.EventBus.Distributed;
-namespace App2
+namespace App1
{
public class App1MessagingService : ITransientDependency
{
@@ -17,21 +17,25 @@ namespace App2
public void Run()
{
- Console.WriteLine("Press ENTER (without writing a message) to stop application...");
- Console.WriteLine();
+ Console.WriteLine("*** Started the APPLICATION 1 ***");
+ Console.WriteLine("Write a message and press ENTER to send to the App2.");
+ Console.WriteLine("Press ENTER (without writing a message) to stop the application.");
string message;
do
{
+ Console.WriteLine();
+ Console.WriteLine("Send message to App2: ");
+
message = Console.ReadLine();
if (!message.IsNullOrEmpty())
{
- _distributedEventBus.Publish(new TextEventData { TextMessage = message });
+ _distributedEventBus.Publish(new App1ToApp2TextEventData(message));
}
else
{
- _distributedEventBus.Publish(new TextEventData { TextMessage = "App1 is exiting. Bye bye...!" });
+ _distributedEventBus.Publish(new App1ToApp2TextEventData("App1 is exiting. Bye bye...!"));
}
} while (!message.IsNullOrEmpty());
diff --git a/samples/RabbitMqEventBus/App1/App1Module.cs b/samples/RabbitMqEventBus/App1/App1Module.cs
index 6eb1280dab..6f608da57e 100644
--- a/samples/RabbitMqEventBus/App1/App1Module.cs
+++ b/samples/RabbitMqEventBus/App1/App1Module.cs
@@ -1,10 +1,12 @@
-using Volo.Abp.EventBus.Distributed.RabbitMq;
+using Volo.Abp.Autofac;
+using Volo.Abp.EventBus.Distributed.RabbitMq;
using Volo.Abp.Modularity;
-namespace App2
+namespace App1
{
[DependsOn(
- typeof(AbpEventBusRabbitMqModule)
+ typeof(AbpEventBusRabbitMqModule),
+ typeof(AbpAutofacModule)
)]
public class App1Module : AbpModule
{
diff --git a/samples/RabbitMqEventBus/App1/App1TextEventHandler.cs b/samples/RabbitMqEventBus/App1/App1TextEventHandler.cs
index 5ee9d2f406..48add1d986 100644
--- a/samples/RabbitMqEventBus/App1/App1TextEventHandler.cs
+++ b/samples/RabbitMqEventBus/App1/App1TextEventHandler.cs
@@ -4,9 +4,12 @@ using SharedModule;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;
-namespace App2
+namespace App1
{
- public class App1TextEventHandler : IDistributedEventHandler, ITransientDependency
+ ///
+ /// Used to listen messages sent to App2 by App1.
+ ///
+ public class App1TextEventHandler : IDistributedEventHandler, ITransientDependency
{
private readonly IDistributedEventBus _distributedEventBus;
@@ -15,18 +18,13 @@ namespace App2
_distributedEventBus = distributedEventBus;
}
- public Task HandleEventAsync(TextEventData eventData)
+ public Task HandleEventAsync(App2ToApp1TextEventData eventData)
{
Console.WriteLine("************************ INCOMING MESSAGE ****************************");
Console.WriteLine(eventData.TextMessage);
Console.WriteLine("**********************************************************************");
- _distributedEventBus.PublishAsync(
- new TextReceivedEventData
- {
- ReceivedText = eventData.TextMessage
- }
- );
+ _distributedEventBus.PublishAsync(new App1TextReceivedEventData(eventData.TextMessage));
return Task.CompletedTask;
}
diff --git a/samples/RabbitMqEventBus/App1/App1TextReceivedEventHandler.cs b/samples/RabbitMqEventBus/App1/App1TextReceivedEventHandler.cs
index 6fe1b45eaa..2e0d22df5a 100644
--- a/samples/RabbitMqEventBus/App1/App1TextReceivedEventHandler.cs
+++ b/samples/RabbitMqEventBus/App1/App1TextReceivedEventHandler.cs
@@ -4,11 +4,14 @@ using SharedModule;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;
-namespace App2
+namespace App1
{
- public class App1TextReceivedEventHandler : IDistributedEventHandler, ITransientDependency
+ ///
+ /// Used to know when App2 has received a message sent by App1.
+ ///
+ public class App1TextReceivedEventHandler : IDistributedEventHandler, ITransientDependency
{
- public Task HandleEventAsync(TextReceivedEventData eventData)
+ public Task HandleEventAsync(App2TextReceivedEventData eventData)
{
Console.WriteLine("--------> App2 has received the message: " + eventData.ReceivedText.TruncateWithPostfix(32));
diff --git a/samples/RabbitMqEventBus/App1/Program.cs b/samples/RabbitMqEventBus/App1/Program.cs
index 38583283c2..aab454523a 100644
--- a/samples/RabbitMqEventBus/App1/Program.cs
+++ b/samples/RabbitMqEventBus/App1/Program.cs
@@ -1,16 +1,21 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
-namespace App2
+namespace App1
{
internal class Program
{
private static void Main(string[] args)
{
- using (var application = AbpApplicationFactory.Create())
+ using (var application = AbpApplicationFactory.Create(options =>
+ {
+ options.UseAutofac();
+ }))
{
application.Initialize();
+ var x = application.ServiceProvider.GetRequiredService();
+
var messagingService = application
.ServiceProvider
.GetRequiredService();
diff --git a/samples/RabbitMqEventBus/App2/App2.csproj b/samples/RabbitMqEventBus/App2/App2.csproj
index 1d59d978ec..7bc8ca1c21 100644
--- a/samples/RabbitMqEventBus/App2/App2.csproj
+++ b/samples/RabbitMqEventBus/App2/App2.csproj
@@ -6,6 +6,7 @@
+
diff --git a/samples/RabbitMqEventBus/App2/App2MessagingService.cs b/samples/RabbitMqEventBus/App2/App2MessagingService.cs
index 03ee9fe071..22157342f2 100644
--- a/samples/RabbitMqEventBus/App2/App2MessagingService.cs
+++ b/samples/RabbitMqEventBus/App2/App2MessagingService.cs
@@ -17,21 +17,25 @@ namespace App2
public void Run()
{
- Console.WriteLine("Press ENTER (without writing a message) to stop application...");
- Console.WriteLine();
+ Console.WriteLine("*** Started the APPLICATION 2 ***");
+ Console.WriteLine("Write a message and press ENTER to send to the App1.");
+ Console.WriteLine("Press ENTER (without writing a message) to stop the application...");
string message;
do
{
+ Console.WriteLine();
+ Console.WriteLine("Send message to App1: ");
+
message = Console.ReadLine();
if (!message.IsNullOrEmpty())
{
- _distributedEventBus.Publish(new TextEventData { TextMessage = message });
+ _distributedEventBus.Publish(new App2ToApp1TextEventData(message));
}
else
{
- _distributedEventBus.Publish(new TextEventData { TextMessage = "App2 is exiting. Bye bye...!" });
+ _distributedEventBus.Publish(new App2ToApp1TextEventData("App2 is exiting. Bye bye...!"));
}
} while (!message.IsNullOrEmpty());
diff --git a/samples/RabbitMqEventBus/App2/App2Module.cs b/samples/RabbitMqEventBus/App2/App2Module.cs
index c2a4959f2c..9f81aa2d4c 100644
--- a/samples/RabbitMqEventBus/App2/App2Module.cs
+++ b/samples/RabbitMqEventBus/App2/App2Module.cs
@@ -1,10 +1,12 @@
-using Volo.Abp.EventBus.Distributed.RabbitMq;
+using Volo.Abp.Autofac;
+using Volo.Abp.EventBus.Distributed.RabbitMq;
using Volo.Abp.Modularity;
namespace App2
{
[DependsOn(
- typeof(AbpEventBusRabbitMqModule)
+ typeof(AbpEventBusRabbitMqModule),
+ typeof(AbpAutofacModule)
)]
public class App2Module : AbpModule
{
diff --git a/samples/RabbitMqEventBus/App2/App2TextEventHandler.cs b/samples/RabbitMqEventBus/App2/App2TextEventHandler.cs
index 16eeaf945d..ac26dd187b 100644
--- a/samples/RabbitMqEventBus/App2/App2TextEventHandler.cs
+++ b/samples/RabbitMqEventBus/App2/App2TextEventHandler.cs
@@ -6,7 +6,10 @@ using Volo.Abp.EventBus.Distributed;
namespace App2
{
- public class App2TextEventHandler : IDistributedEventHandler, ITransientDependency
+ ///
+ /// Used to listen messages sent to App2 by App1.
+ ///
+ public class App2TextEventHandler : IDistributedEventHandler, ITransientDependency
{
private readonly IDistributedEventBus _distributedEventBus;
@@ -15,18 +18,13 @@ namespace App2
_distributedEventBus = distributedEventBus;
}
- public Task HandleEventAsync(TextEventData eventData)
+ public Task HandleEventAsync(App1ToApp2TextEventData eventData)
{
Console.WriteLine("************************ INCOMING MESSAGE ****************************");
Console.WriteLine(eventData.TextMessage);
Console.WriteLine("**********************************************************************");
- _distributedEventBus.PublishAsync(
- new TextReceivedEventData
- {
- ReceivedText = eventData.TextMessage
- }
- );
+ _distributedEventBus.PublishAsync(new App2TextReceivedEventData(eventData.TextMessage));
return Task.CompletedTask;
}
diff --git a/samples/RabbitMqEventBus/App2/App2TextReceivedEventHandler.cs b/samples/RabbitMqEventBus/App2/App2TextReceivedEventHandler.cs
index 308cedf7d8..fde68aa615 100644
--- a/samples/RabbitMqEventBus/App2/App2TextReceivedEventHandler.cs
+++ b/samples/RabbitMqEventBus/App2/App2TextReceivedEventHandler.cs
@@ -6,9 +6,12 @@ using Volo.Abp.EventBus.Distributed;
namespace App2
{
- public class App2TextReceivedEventHandler : IDistributedEventHandler, ITransientDependency
+ ///
+ /// Used to know when App1 has received a message sent by App2.
+ ///
+ public class App2TextReceivedEventHandler : IDistributedEventHandler, ITransientDependency
{
- public Task HandleEventAsync(TextReceivedEventData eventData)
+ public Task HandleEventAsync(App1TextReceivedEventData eventData)
{
Console.WriteLine("--------> App1 has received the message: " + eventData.ReceivedText.TruncateWithPostfix(32));
diff --git a/samples/RabbitMqEventBus/App2/Program.cs b/samples/RabbitMqEventBus/App2/Program.cs
index c13d9a1dee..2686c54e8f 100644
--- a/samples/RabbitMqEventBus/App2/Program.cs
+++ b/samples/RabbitMqEventBus/App2/Program.cs
@@ -7,7 +7,10 @@ namespace App2
{
private static void Main(string[] args)
{
- using (var application = AbpApplicationFactory.Create())
+ using (var application = AbpApplicationFactory.Create(options =>
+ {
+ options.UseAutofac();
+ }))
{
application.Initialize();
diff --git a/samples/RabbitMqEventBus/SharedModule/App1TextReceivedEventData.cs b/samples/RabbitMqEventBus/SharedModule/App1TextReceivedEventData.cs
new file mode 100644
index 0000000000..0e01f74b84
--- /dev/null
+++ b/samples/RabbitMqEventBus/SharedModule/App1TextReceivedEventData.cs
@@ -0,0 +1,23 @@
+using Volo.Abp.EventBus;
+
+namespace SharedModule
+{
+ ///
+ /// Used to indicate that App2 has received a text message.
+ ///
+ [EventName("Test.App1TextReceived")] //Optional event name
+ public class App1TextReceivedEventData
+ {
+ public string ReceivedText { get; set; }
+
+ public App1TextReceivedEventData()
+ {
+
+ }
+
+ public App1TextReceivedEventData(string receivedText)
+ {
+ ReceivedText = receivedText;
+ }
+ }
+}
diff --git a/samples/RabbitMqEventBus/SharedModule/App1ToApp2TextEventData.cs b/samples/RabbitMqEventBus/SharedModule/App1ToApp2TextEventData.cs
new file mode 100644
index 0000000000..56d2c31186
--- /dev/null
+++ b/samples/RabbitMqEventBus/SharedModule/App1ToApp2TextEventData.cs
@@ -0,0 +1,23 @@
+using Volo.Abp.EventBus;
+
+namespace SharedModule
+{
+ ///
+ /// Used to send a text message from App1 to App2.
+ ///
+ [EventName("Test.App1ToApp2Text")] //Optional event name
+ public class App1ToApp2TextEventData
+ {
+ public string TextMessage { get; set; }
+
+ public App1ToApp2TextEventData()
+ {
+
+ }
+
+ public App1ToApp2TextEventData(string textMessage)
+ {
+ TextMessage = textMessage;
+ }
+ }
+}
diff --git a/samples/RabbitMqEventBus/SharedModule/App2TextReceivedEventData.cs b/samples/RabbitMqEventBus/SharedModule/App2TextReceivedEventData.cs
new file mode 100644
index 0000000000..c3ac4bf9bb
--- /dev/null
+++ b/samples/RabbitMqEventBus/SharedModule/App2TextReceivedEventData.cs
@@ -0,0 +1,23 @@
+using Volo.Abp.EventBus;
+
+namespace SharedModule
+{
+ ///
+ /// Used to indicate that App2 has received a text message.
+ ///
+ [EventName("Test.App2TextReceived")] //Optional event name
+ public class App2TextReceivedEventData
+ {
+ public string ReceivedText { get; set; }
+
+ public App2TextReceivedEventData()
+ {
+
+ }
+
+ public App2TextReceivedEventData(string receivedText)
+ {
+ ReceivedText = receivedText;
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/RabbitMqEventBus/SharedModule/App2ToApp1TextEventData.cs b/samples/RabbitMqEventBus/SharedModule/App2ToApp1TextEventData.cs
new file mode 100644
index 0000000000..2943661f7d
--- /dev/null
+++ b/samples/RabbitMqEventBus/SharedModule/App2ToApp1TextEventData.cs
@@ -0,0 +1,23 @@
+using Volo.Abp.EventBus;
+
+namespace SharedModule
+{
+ ///
+ /// Used to send a text message from App2 to App1.
+ ///
+ [EventName("Test.App2ToApp1Text")] //Optional event name
+ public class App2ToApp1TextEventData
+ {
+ public string TextMessage { get; set; }
+
+ public App2ToApp1TextEventData()
+ {
+
+ }
+
+ public App2ToApp1TextEventData(string textMessage)
+ {
+ TextMessage = textMessage;
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/RabbitMqEventBus/SharedModule/SharedModule.csproj b/samples/RabbitMqEventBus/SharedModule/SharedModule.csproj
index dbdcea46b6..c659ddff0b 100644
--- a/samples/RabbitMqEventBus/SharedModule/SharedModule.csproj
+++ b/samples/RabbitMqEventBus/SharedModule/SharedModule.csproj
@@ -4,4 +4,8 @@
netstandard2.0
+
+
+
+
diff --git a/samples/RabbitMqEventBus/SharedModule/TextEventData.cs b/samples/RabbitMqEventBus/SharedModule/TextEventData.cs
deleted file mode 100644
index 4b88a9e7bd..0000000000
--- a/samples/RabbitMqEventBus/SharedModule/TextEventData.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace SharedModule
-{
- public class TextEventData
- {
- public string TextMessage { get; set; }
- }
-}
diff --git a/samples/RabbitMqEventBus/SharedModule/TextReceivedEventData.cs b/samples/RabbitMqEventBus/SharedModule/TextReceivedEventData.cs
deleted file mode 100644
index 825fb19aac..0000000000
--- a/samples/RabbitMqEventBus/SharedModule/TextReceivedEventData.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace SharedModule
-{
- public class TextReceivedEventData
- {
- public string ReceivedText { get; set; }
- }
-}