Created sample rabbitmq messaging application

pull/660/head
Halil ibrahim Kalkan 7 years ago
parent 7759d3244f
commit 55981f714c

@ -0,0 +1,36 @@
using System;
using JetBrains.Annotations;
using Volo.Abp.Threading;
namespace Volo.Abp.EventBus
{
public static class EventBusExtensions
{
/// <summary>
/// Triggers an event.
/// </summary>
/// <typeparam name="TEvent">Event type</typeparam>
/// <param name="eventBus">Event bus instance</param>
/// <param name="eventData">Related data for the event</param>
public static void Publish<TEvent>([NotNull] this IEventBus eventBus, [NotNull] TEvent eventData)
where TEvent : class
{
Check.NotNull(eventBus, nameof(eventBus));
AsyncHelper.RunSync(() => eventBus.PublishAsync(eventData));
}
/// <summary>
/// Triggers an event.
/// </summary>
/// <param name="eventBus">Event bus instance</param>
/// <param name="eventType">Event type</param>
/// <param name="eventData">Related data for the event</param>
public static void Publish([NotNull] this IEventBus eventBus, [NotNull] Type eventType, [NotNull] object eventData)
{
Check.NotNull(eventBus, nameof(eventBus));
AsyncHelper.RunSync(() => eventBus.PublishAsync(eventType, eventData));
}
}
}

@ -6,7 +6,7 @@ namespace Volo.Abp.EventBus
public interface IEventBus
{
/// <summary>
/// Triggers an event asynchronously.
/// Triggers an event.
/// </summary>
/// <typeparam name="TEvent">Event type</typeparam>
/// <param name="eventData">Related data for the event</param>
@ -15,7 +15,7 @@ namespace Volo.Abp.EventBus
where TEvent : class;
/// <summary>
/// Triggers an event asynchronously.
/// Triggers an event.
/// </summary>
/// <param name="eventType">Event type</param>
/// <param name="eventData">Related data for the event</param>

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\framework\src\Volo.Abp.EventBus.RabbitMQ\Volo.Abp.EventBus.RabbitMQ.csproj" />
<ProjectReference Include="..\SharedModule\SharedModule.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,40 @@
using System;
using SharedModule;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus;
using Volo.Abp.EventBus.Distributed;
namespace App2
{
public class App1MessagingService : ITransientDependency
{
private readonly IDistributedEventBus _distributedEventBus;
public App1MessagingService(IDistributedEventBus distributedEventBus)
{
_distributedEventBus = distributedEventBus;
}
public void Run()
{
Console.WriteLine("Press ENTER (without writing a message) to stop application...");
Console.WriteLine();
string message;
do
{
message = Console.ReadLine();
if (!message.IsNullOrEmpty())
{
_distributedEventBus.Publish(new TextEventData { TextMessage = message });
}
else
{
_distributedEventBus.Publish(new TextEventData { TextMessage = "App1 is exiting. Bye bye...!" });
}
} while (!message.IsNullOrEmpty());
}
}
}

@ -0,0 +1,20 @@
using Volo.Abp.EventBus.Distributed.RabbitMq;
using Volo.Abp.Modularity;
namespace App2
{
[DependsOn(
typeof(AbpEventBusRabbitMqModule)
)]
public class App1Module : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<RabbitMqDistributedEventBusOptions>(options =>
{
options.ClientName = "TestApp1";
options.ExchangeName = "TestMessages";
});
}
}
}

@ -0,0 +1,34 @@
using System;
using System.Threading.Tasks;
using SharedModule;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;
namespace App2
{
public class App1TextEventHandler : IDistributedEventHandler<TextEventData>, ITransientDependency
{
private readonly IDistributedEventBus _distributedEventBus;
public App1TextEventHandler(IDistributedEventBus distributedEventBus)
{
_distributedEventBus = distributedEventBus;
}
public Task HandleEventAsync(TextEventData eventData)
{
Console.WriteLine("************************ INCOMING MESSAGE ****************************");
Console.WriteLine(eventData.TextMessage);
Console.WriteLine("**********************************************************************");
_distributedEventBus.PublishAsync(
new TextReceivedEventData
{
ReceivedText = eventData.TextMessage
}
);
return Task.CompletedTask;
}
}
}

@ -0,0 +1,18 @@
using System;
using System.Threading.Tasks;
using SharedModule;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;
namespace App2
{
public class App1TextReceivedEventHandler : IDistributedEventHandler<TextReceivedEventData>, ITransientDependency
{
public Task HandleEventAsync(TextReceivedEventData eventData)
{
Console.WriteLine("--------> App2 has received the message: " + eventData.ReceivedText.TruncateWithPostfix(32));
return Task.CompletedTask;
}
}
}

@ -0,0 +1,24 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
namespace App2
{
internal class Program
{
private static void Main(string[] args)
{
using (var application = AbpApplicationFactory.Create<App1Module>())
{
application.Initialize();
var messagingService = application
.ServiceProvider
.GetRequiredService<App1MessagingService>();
messagingService.Run();
application.Shutdown();
}
}
}
}

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\framework\src\Volo.Abp.EventBus.RabbitMQ\Volo.Abp.EventBus.RabbitMQ.csproj" />
<ProjectReference Include="..\SharedModule\SharedModule.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,40 @@
using System;
using SharedModule;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus;
using Volo.Abp.EventBus.Distributed;
namespace App2
{
public class App2MessagingService : ITransientDependency
{
private readonly IDistributedEventBus _distributedEventBus;
public App2MessagingService(IDistributedEventBus distributedEventBus)
{
_distributedEventBus = distributedEventBus;
}
public void Run()
{
Console.WriteLine("Press ENTER (without writing a message) to stop application...");
Console.WriteLine();
string message;
do
{
message = Console.ReadLine();
if (!message.IsNullOrEmpty())
{
_distributedEventBus.Publish(new TextEventData { TextMessage = message });
}
else
{
_distributedEventBus.Publish(new TextEventData { TextMessage = "App2 is exiting. Bye bye...!" });
}
} while (!message.IsNullOrEmpty());
}
}
}

@ -0,0 +1,20 @@
using Volo.Abp.EventBus.Distributed.RabbitMq;
using Volo.Abp.Modularity;
namespace App2
{
[DependsOn(
typeof(AbpEventBusRabbitMqModule)
)]
public class App2Module : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<RabbitMqDistributedEventBusOptions>(options =>
{
options.ClientName = "TestApp2";
options.ExchangeName = "TestMessages";
});
}
}
}

@ -0,0 +1,34 @@
using System;
using System.Threading.Tasks;
using SharedModule;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;
namespace App2
{
public class App2TextEventHandler : IDistributedEventHandler<TextEventData>, ITransientDependency
{
private readonly IDistributedEventBus _distributedEventBus;
public App2TextEventHandler(IDistributedEventBus distributedEventBus)
{
_distributedEventBus = distributedEventBus;
}
public Task HandleEventAsync(TextEventData eventData)
{
Console.WriteLine("************************ INCOMING MESSAGE ****************************");
Console.WriteLine(eventData.TextMessage);
Console.WriteLine("**********************************************************************");
_distributedEventBus.PublishAsync(
new TextReceivedEventData
{
ReceivedText = eventData.TextMessage
}
);
return Task.CompletedTask;
}
}
}

@ -0,0 +1,18 @@
using System;
using System.Threading.Tasks;
using SharedModule;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;
namespace App2
{
public class App2TextReceivedEventHandler : IDistributedEventHandler<TextReceivedEventData>, ITransientDependency
{
public Task HandleEventAsync(TextReceivedEventData eventData)
{
Console.WriteLine("--------> App1 has received the message: " + eventData.ReceivedText.TruncateWithPostfix(32));
return Task.CompletedTask;
}
}
}

@ -0,0 +1,24 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
namespace App2
{
internal class Program
{
private static void Main(string[] args)
{
using (var application = AbpApplicationFactory.Create<App2Module>())
{
application.Initialize();
var messagingService = application
.ServiceProvider
.GetRequiredService<App2MessagingService>();
messagingService.Run();
application.Shutdown();
}
}
}
}

@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2016
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "App1", "App1\App1.csproj", "{2C93AFEF-1677-4591-8245-35D5E0F99B03}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedModule", "SharedModule\SharedModule.csproj", "{D6F948FB-699B-45D7-8B79-F9D43B627B68}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App2", "App2\App2.csproj", "{A5FE0CEF-C472-47DD-9F2B-DFFFA33B8523}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2C93AFEF-1677-4591-8245-35D5E0F99B03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C93AFEF-1677-4591-8245-35D5E0F99B03}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C93AFEF-1677-4591-8245-35D5E0F99B03}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C93AFEF-1677-4591-8245-35D5E0F99B03}.Release|Any CPU.Build.0 = Release|Any CPU
{D6F948FB-699B-45D7-8B79-F9D43B627B68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D6F948FB-699B-45D7-8B79-F9D43B627B68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6F948FB-699B-45D7-8B79-F9D43B627B68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6F948FB-699B-45D7-8B79-F9D43B627B68}.Release|Any CPU.Build.0 = Release|Any CPU
{A5FE0CEF-C472-47DD-9F2B-DFFFA33B8523}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5FE0CEF-C472-47DD-9F2B-DFFFA33B8523}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5FE0CEF-C472-47DD-9F2B-DFFFA33B8523}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5FE0CEF-C472-47DD-9F2B-DFFFA33B8523}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {44A91B65-F109-4FD0-B6C0-63C052A5BEEB}
EndGlobalSection
EndGlobal

@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>

@ -0,0 +1,7 @@
namespace SharedModule
{
public class TextEventData
{
public string TextMessage { get; set; }
}
}

@ -0,0 +1,7 @@
namespace SharedModule
{
public class TextReceivedEventData
{
public string ReceivedText { get; set; }
}
}
Loading…
Cancel
Save