Browse Source

Fix: IEventBus only has PublishAsync method - replaced Publish

pull/1683/head
Dillan Cagnetta 7 years ago
parent
commit
257257c834
  1. 12
      samples/RabbitMqEventBus/App1/App1MessagingService.cs
  2. 6
      samples/RabbitMqEventBus/App1/App1TextEventHandler.cs
  3. 7
      samples/RabbitMqEventBus/App1/Program.cs
  4. 12
      samples/RabbitMqEventBus/App2/App2MessagingService.cs
  5. 6
      samples/RabbitMqEventBus/App2/App2TextEventHandler.cs
  6. 7
      samples/RabbitMqEventBus/App2/Program.cs

12
samples/RabbitMqEventBus/App1/App1MessagingService.cs

@ -1,7 +1,7 @@
using System; using SharedModule;
using SharedModule; using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus;
using Volo.Abp.EventBus.Distributed; using Volo.Abp.EventBus.Distributed;
namespace App1 namespace App1
@ -15,7 +15,7 @@ namespace App1
_distributedEventBus = distributedEventBus; _distributedEventBus = distributedEventBus;
} }
public void Run() public async Task RunAsync()
{ {
Console.WriteLine("*** Started the APPLICATION 1 ***"); Console.WriteLine("*** Started the APPLICATION 1 ***");
Console.WriteLine("Write a message and press ENTER to send to the App2."); Console.WriteLine("Write a message and press ENTER to send to the App2.");
@ -30,11 +30,11 @@ namespace App1
if (!message.IsNullOrEmpty()) if (!message.IsNullOrEmpty())
{ {
_distributedEventBus.Publish(new App1ToApp2TextEventData(message)); await _distributedEventBus.PublishAsync(new App1ToApp2TextEventData(message));
} }
else else
{ {
_distributedEventBus.Publish(new App1ToApp2TextEventData("App1 is exiting. Bye bye...!")); await _distributedEventBus.PublishAsync(new App1ToApp2TextEventData("App1 is exiting. Bye bye...!"));
} }
} while (!message.IsNullOrEmpty()); } while (!message.IsNullOrEmpty());

6
samples/RabbitMqEventBus/App1/App1TextEventHandler.cs

@ -18,16 +18,14 @@ namespace App1
_distributedEventBus = distributedEventBus; _distributedEventBus = distributedEventBus;
} }
public Task HandleEventAsync(App2ToApp1TextEventData eventData) public async Task HandleEventAsync(App2ToApp1TextEventData eventData)
{ {
Console.WriteLine("************************ INCOMING MESSAGE ****************************"); Console.WriteLine("************************ INCOMING MESSAGE ****************************");
Console.WriteLine(eventData.TextMessage); Console.WriteLine(eventData.TextMessage);
Console.WriteLine("**********************************************************************"); Console.WriteLine("**********************************************************************");
Console.WriteLine(); Console.WriteLine();
_distributedEventBus.PublishAsync(new App1TextReceivedEventData(eventData.TextMessage)); await _distributedEventBus.PublishAsync(new App1TextReceivedEventData(eventData.TextMessage));
return Task.CompletedTask;
} }
} }
} }

7
samples/RabbitMqEventBus/App1/Program.cs

@ -1,11 +1,12 @@
using Microsoft.Extensions.DependencyInjection; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp; using Volo.Abp;
namespace App1 namespace App1
{ {
internal class Program internal class Program
{ {
private static void Main(string[] args) private static async Task Main(string[] args)
{ {
using (var application = AbpApplicationFactory.Create<App1Module>(options => using (var application = AbpApplicationFactory.Create<App1Module>(options =>
{ {
@ -18,7 +19,7 @@ namespace App1
.ServiceProvider .ServiceProvider
.GetRequiredService<App1MessagingService>(); .GetRequiredService<App1MessagingService>();
messagingService.Run(); await messagingService.RunAsync();
application.Shutdown(); application.Shutdown();
} }

12
samples/RabbitMqEventBus/App2/App2MessagingService.cs

@ -1,7 +1,7 @@
using System; using SharedModule;
using SharedModule; using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus;
using Volo.Abp.EventBus.Distributed; using Volo.Abp.EventBus.Distributed;
namespace App2 namespace App2
@ -15,7 +15,7 @@ namespace App2
_distributedEventBus = distributedEventBus; _distributedEventBus = distributedEventBus;
} }
public void Run() public async Task RunAsync()
{ {
Console.WriteLine("*** Started the APPLICATION 2 ***"); Console.WriteLine("*** Started the APPLICATION 2 ***");
Console.WriteLine("Write a message and press ENTER to send to the App1."); Console.WriteLine("Write a message and press ENTER to send to the App1.");
@ -30,11 +30,11 @@ namespace App2
if (!message.IsNullOrEmpty()) if (!message.IsNullOrEmpty())
{ {
_distributedEventBus.Publish(new App2ToApp1TextEventData(message)); await _distributedEventBus.PublishAsync(new App2ToApp1TextEventData(message));
} }
else else
{ {
_distributedEventBus.Publish(new App2ToApp1TextEventData("App2 is exiting. Bye bye...!")); await _distributedEventBus.PublishAsync(new App2ToApp1TextEventData("App2 is exiting. Bye bye...!"));
} }
} while (!message.IsNullOrEmpty()); } while (!message.IsNullOrEmpty());

6
samples/RabbitMqEventBus/App2/App2TextEventHandler.cs

@ -18,16 +18,14 @@ namespace App2
_distributedEventBus = distributedEventBus; _distributedEventBus = distributedEventBus;
} }
public Task HandleEventAsync(App1ToApp2TextEventData eventData) public async Task HandleEventAsync(App1ToApp2TextEventData eventData)
{ {
Console.WriteLine("************************ INCOMING MESSAGE ****************************"); Console.WriteLine("************************ INCOMING MESSAGE ****************************");
Console.WriteLine(eventData.TextMessage); Console.WriteLine(eventData.TextMessage);
Console.WriteLine("**********************************************************************"); Console.WriteLine("**********************************************************************");
Console.WriteLine(); Console.WriteLine();
_distributedEventBus.PublishAsync(new App2TextReceivedEventData(eventData.TextMessage)); await _distributedEventBus.PublishAsync(new App2TextReceivedEventData(eventData.TextMessage));
return Task.CompletedTask;
} }
} }
} }

7
samples/RabbitMqEventBus/App2/Program.cs

@ -1,11 +1,12 @@
using Microsoft.Extensions.DependencyInjection; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp; using Volo.Abp;
namespace App2 namespace App2
{ {
internal class Program internal class Program
{ {
private static void Main(string[] args) private static async Task Main(string[] args)
{ {
using (var application = AbpApplicationFactory.Create<App2Module>(options => using (var application = AbpApplicationFactory.Create<App2Module>(options =>
{ {
@ -18,7 +19,7 @@ namespace App2
.ServiceProvider .ServiceProvider
.GetRequiredService<App2MessagingService>(); .GetRequiredService<App2MessagingService>();
messagingService.Run(); await messagingService.RunAsync();
application.Shutdown(); application.Shutdown();
} }

Loading…
Cancel
Save