├── InPoint ├── License.txt ├── png-transparent-molecule-molecular-biology-computer-icons-others-biology-chemistry-dna-thumbnail.ico ├── InPointMessagePublisher.cs ├── Tests │ ├── EventHubPublisherTests.cs │ ├── EventGridPublisherTests.cs │ ├── RabbitMqPublisherTests.cs │ └── ServiceBusPublisherTests.cs ├── Factory │ └── InPointPublisherFactory.cs ├── EventHubServiceCollectionExtensions.cs ├── ServiceBusServiceCollectionExtensions.cs ├── EventGridServiceCollectionExtensions.cs ├── InPointServiceCollectionExtensions.cs ├── RabbitMQServiceCollectionExtensions.cs └── InPoint.csproj ├── .gitignore ├── publish-subscribe.png ├── InPoint.sln └── README.md /InPoint/License.txt: -------------------------------------------------------------------------------- 1 | "license": "MIT" -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | SAMS/SAMS.Application.API.zip 2 | -------------------------------------------------------------------------------- /publish-subscribe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ethan0007/InPoint/main/publish-subscribe.png -------------------------------------------------------------------------------- /InPoint/png-transparent-molecule-molecular-biology-computer-icons-others-biology-chemistry-dna-thumbnail.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ethan0007/InPoint/main/InPoint/png-transparent-molecule-molecular-biology-computer-icons-others-biology-chemistry-dna-thumbnail.ico -------------------------------------------------------------------------------- /InPoint/InPointMessagePublisher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | /* 7 | * OWNER: JOEVER MONCEDA 8 | */ 9 | namespace InPoint 10 | { 11 | public interface InPointMessagePublisher 12 | { 13 | Task Publish(string message, 14 | string? subject = null, 15 | string? eventType = null, 16 | string? dataVersion = null); 17 | } 18 | 19 | 20 | public interface IRabbitMQPublisher : InPointMessagePublisher { } 21 | public interface IEventHubPublisher : InPointMessagePublisher { } 22 | public interface IServiceBusPublisher : InPointMessagePublisher { } 23 | public interface IEventGridPublisher : InPointMessagePublisher { } 24 | } 25 | -------------------------------------------------------------------------------- /InPoint/Tests/EventHubPublisherTests.cs: -------------------------------------------------------------------------------- 1 | using Azure.Messaging.EventHubs.Producer; 2 | using Moq; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using Xunit; 9 | /* 10 | * OWNER: JOEVER MONCEDA 11 | */ 12 | namespace InPoint.Tests 13 | { 14 | public class EventHubPublisherTests 15 | { 16 | [Fact] 17 | public async Task Publish_ShouldSendEventToEventHub() 18 | { 19 | // Arrange 20 | var mockClient = new Mock(); 21 | var publisher = new EventHubPublisher(mockClient.Object); 22 | 23 | // Act 24 | await publisher.Publish("Test Message"); 25 | 26 | // Assert 27 | mockClient.Verify(client => client.SendAsync(It.IsAny(), It.IsAny()), Times.Once); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /InPoint/Tests/EventGridPublisherTests.cs: -------------------------------------------------------------------------------- 1 | using Azure.Messaging.EventGrid; 2 | using Moq; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using Xunit; 9 | /* 10 | * OWNER: JOEVER MONCEDA 11 | */ 12 | namespace InPoint.Tests 13 | { 14 | public class EventGridPublisherTests 15 | { 16 | [Fact] 17 | public async Task Publish_ShouldSendEventToEventGrid() 18 | { 19 | // Arrange 20 | var mockClient = new Mock(); 21 | var publisher = new EventGridPublisher(mockClient.Object); 22 | 23 | // Act 24 | await publisher.Publish("Test Message"); 25 | 26 | // Assert 27 | mockClient.Verify(client => client.SendEventAsync((EventGridEvent) 28 | It.IsAny>(), 29 | It.IsAny()), Times.Once); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /InPoint/Tests/RabbitMqPublisherTests.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Options; 2 | using Moq; 3 | using RabbitMQ.Client; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using Xunit; 10 | /* 11 | * OWNER: JOEVER MONCEDA 12 | */ 13 | namespace InPoint.Tests 14 | { 15 | public class RabbitMqPublisherTests 16 | { 17 | [Fact] 18 | public void Publish_ShouldSendMessageToQueue() 19 | { 20 | // Arrange 21 | var mockChannel = new Mock(); 22 | var options = Options.Create(new RabbitMqOptions { QueueName = "testQueue" }); 23 | var publisher = new RabbitMQPublisher(mockChannel.Object, options); 24 | 25 | // Act 26 | publisher.Publish("Test Message"); 27 | 28 | // Assert 29 | mockChannel.Verify(ch => ch.BasicPublish( 30 | It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny() 31 | ), Times.Once); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /InPoint.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.11.35219.272 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InPoint", "InPoint\InPoint.csproj", "{58899D46-1445-4601-A224-027500AC55F3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {58899D46-1445-4601-A224-027500AC55F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {58899D46-1445-4601-A224-027500AC55F3}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {58899D46-1445-4601-A224-027500AC55F3}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {58899D46-1445-4601-A224-027500AC55F3}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {9AF00E0A-ABF4-438C-819A-4D7DD970DE59} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /InPoint/Tests/ServiceBusPublisherTests.cs: -------------------------------------------------------------------------------- 1 | using Azure.Messaging.ServiceBus; 2 | using Microsoft.Extensions.Options; 3 | using Moq; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using Xunit; 10 | /* 11 | * OWNER: JOEVER MONCEDA 12 | */ 13 | namespace InPoint.Tests 14 | { 15 | public class ServiceBusPublisherTests 16 | { 17 | [Fact] 18 | public async Task Publish_ShouldSendMessageToServiceBusQueue() 19 | { 20 | // Arrange 21 | var mockClient = new Mock(); 22 | var mockSender = new Mock(); 23 | mockClient.Setup(client => client.CreateSender(It.IsAny())).Returns(mockSender.Object); 24 | 25 | var publisher = new ServiceBusPublisher(mockClient.Object, Options.Create(new ServiceBusOptions { QueueName = "testQueue" })); 26 | 27 | // Act 28 | await publisher.Publish("Test Message"); 29 | 30 | // Assert 31 | mockSender.Verify(sender => sender.SendMessageAsync(It.IsAny(), It.IsAny()), Times.Once); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /InPoint/Factory/InPointPublisherFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | /* 8 | * OWNER: JOEVER MONCEDA 9 | */ 10 | namespace InPoint.Factory 11 | { 12 | public class InPointPublisherFactory 13 | { 14 | private readonly IServiceProvider _serviceProvider; 15 | 16 | public InPointPublisherFactory(IServiceProvider serviceProvider) 17 | { 18 | _serviceProvider = serviceProvider; 19 | } 20 | 21 | public InPointMessagePublisher GetPublisher(string provider) 22 | { 23 | return provider switch 24 | { 25 | "RabbitMQ" => _serviceProvider.GetRequiredService(), 26 | "EventHub" => _serviceProvider.GetRequiredService(), 27 | "ServiceBus" => _serviceProvider.GetRequiredService(), 28 | "EventGrid" => _serviceProvider.GetRequiredService(), 29 | _ => throw new ArgumentException($"Unsupported messaging provider: {provider}"), 30 | }; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /InPoint/EventHubServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Azure.Messaging.EventHubs; 2 | using Azure.Messaging.EventHubs.Producer; 3 | using Microsoft.Extensions.Configuration; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | /* 11 | * OWNER: JOEVER MONCEDA 12 | */ 13 | namespace InPoint 14 | { 15 | public static class EventHubServiceCollectionExtensions 16 | { 17 | public static IServiceCollection ConfigureEventHub(this IServiceCollection services, IConfiguration eventHubConfig) 18 | { 19 | var eventHubOptions = new EventHubOptions(); 20 | eventHubConfig.Bind(eventHubOptions); 21 | 22 | services.AddSingleton(new EventHubProducerClient(eventHubOptions.ConnectionString, eventHubOptions.EventHubName)); 23 | services.AddSingleton(); 24 | 25 | return services; 26 | } 27 | } 28 | 29 | public class EventHubOptions 30 | { 31 | public string ConnectionString { get; set; } 32 | public string EventHubName { get; set; } 33 | } 34 | 35 | public class EventHubPublisher : IEventHubPublisher 36 | { 37 | private readonly EventHubProducerClient _producerClient; 38 | 39 | public EventHubPublisher(EventHubProducerClient producerClient) 40 | { 41 | _producerClient = producerClient; 42 | } 43 | 44 | public async Task Publish(string message, 45 | string? subject = null, 46 | string? eventType = null, 47 | string? dataVersion = null) 48 | { 49 | using EventDataBatch eventBatch = await _producerClient.CreateBatchAsync(); 50 | eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes(message))); 51 | 52 | await _producerClient.SendAsync(eventBatch); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /InPoint/ServiceBusServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Azure.Messaging.ServiceBus; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Microsoft.Extensions.Options; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace InPoint 12 | { 13 | public static class ServiceBusServiceCollectionExtensions 14 | { 15 | public static IServiceCollection ConfigureServiceBus(this IServiceCollection services, IConfiguration serviceBusConfig) 16 | { 17 | var serviceBusOptions = new ServiceBusOptions(); 18 | serviceBusConfig.Bind(serviceBusOptions); 19 | 20 | services.AddSingleton(new ServiceBusClient(serviceBusOptions.ConnectionString)); 21 | services.AddSingleton(); 22 | 23 | return services; 24 | } 25 | } 26 | 27 | public class ServiceBusOptions 28 | { 29 | public string ConnectionString { get; set; } 30 | public string QueueName { get; set; } 31 | } 32 | 33 | public class ServiceBusPublisher : IServiceBusPublisher 34 | { 35 | private readonly ServiceBusClient _client; 36 | private readonly ServiceBusOptions _options; 37 | 38 | public ServiceBusPublisher(ServiceBusClient client, IOptions options) 39 | { 40 | _client = client; 41 | _options = options.Value; 42 | } 43 | 44 | public async Task Publish(string message, 45 | string? subject = null, 46 | string? eventType = null, 47 | string? dataVersion = null) 48 | { 49 | ServiceBusSender sender = _client.CreateSender(_options.QueueName); 50 | ServiceBusMessage busMessage = new ServiceBusMessage(message); 51 | 52 | await sender.SendMessageAsync(busMessage); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /InPoint/EventGridServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Azure.Messaging.EventGrid; 2 | using Azure; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using Microsoft.Extensions.Configuration; 10 | /* 11 | * OWNER: JOEVER MONCEDA 12 | */ 13 | namespace InPoint 14 | { 15 | public static class EventGridServiceCollectionExtensions 16 | { 17 | public static IServiceCollection ConfigureEventGrid(this IServiceCollection services, IConfiguration eventGridConfig) 18 | { 19 | var eventGridOptions = new EventGridOptions(); 20 | eventGridConfig.Bind(eventGridOptions); 21 | 22 | services.AddSingleton(new EventGridPublisherClient(new Uri(eventGridOptions.Endpoint), new AzureKeyCredential(eventGridOptions.AccessKey))); 23 | services.AddSingleton(); 24 | 25 | return services; 26 | } 27 | } 28 | 29 | public class EventGridOptions 30 | { 31 | public string Endpoint { get; set; } 32 | public string AccessKey { get; set; } 33 | } 34 | 35 | public class EventGridPublisher : IEventGridPublisher 36 | { 37 | private readonly EventGridPublisherClient _client; 38 | 39 | public EventGridPublisher(EventGridPublisherClient client) 40 | { 41 | _client = client; 42 | } 43 | 44 | public async Task Publish(string message, 45 | string? subject = null, 46 | string? eventType = null, 47 | string? dataVersion = null) 48 | { 49 | EventGridEvent eventGridEvent = new EventGridEvent( 50 | subject: subject, 51 | eventType: eventType, 52 | dataVersion: dataVersion, 53 | data: message 54 | ); 55 | 56 | await _client.SendEventAsync(eventGridEvent); 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /InPoint/InPointServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using InPoint.Factory; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | /* 5 | * OWNER: JOEVER MONCEDA 6 | */ 7 | namespace InPoint 8 | { 9 | public static class InPointServiceCollectionExtensions 10 | { 11 | public static IServiceCollection AddInPointMessaging(this IServiceCollection services, IConfiguration config) 12 | { 13 | var providers = config.GetSection("MessagingProvider").Get(); 14 | 15 | if (!providers.Any()) throw new ArgumentException("No messaging provider!"); 16 | 17 | foreach (var provider in providers) 18 | { 19 | switch (provider) 20 | { 21 | case "RabbitMQ": 22 | services.ConfigureRabbitMQ(config.GetSection("RabbitMQ")); 23 | services.AddScoped(); 24 | break; 25 | case "EventHub": 26 | services.ConfigureEventHub(config.GetSection("EventHub")); 27 | services.AddScoped(); 28 | break; 29 | case "ServiceBus": 30 | services.ConfigureServiceBus(config.GetSection("ServiceBus")); 31 | services.AddScoped(); 32 | break; 33 | case "EventGrid": 34 | services.ConfigureEventGrid(config.GetSection("EventGrid")); 35 | services.AddScoped(); 36 | break; 37 | default: 38 | throw new ArgumentException($"Unsupported messaging provider: {provider}"); 39 | } 40 | } 41 | 42 | services.AddScoped(); 43 | 44 | return services; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /InPoint/RabbitMQServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Configuration; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using Microsoft.Extensions.Options; 4 | using RabbitMQ.Client; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace InPoint 12 | { 13 | public static class RabbitMQServiceCollectionExtensions 14 | { 15 | public static IServiceCollection ConfigureRabbitMQ(this IServiceCollection services, IConfiguration rabbitMQConfig) 16 | { 17 | var rabbitMqOptions = new RabbitMqOptions(); 18 | rabbitMQConfig.Bind(rabbitMqOptions); 19 | 20 | var connectionFactory = new ConnectionFactory 21 | { 22 | HostName = rabbitMqOptions.Host, 23 | UserName = rabbitMqOptions.Username, 24 | Password = rabbitMqOptions.Password 25 | }; 26 | 27 | services.AddSingleton(connectionFactory); 28 | services.AddSingleton(sp => connectionFactory.CreateConnection()); 29 | services.AddSingleton(sp => sp.GetRequiredService().CreateModel()); 30 | 31 | services.AddSingleton(); 32 | 33 | return services; 34 | } 35 | } 36 | 37 | public class RabbitMqOptions 38 | { 39 | public string Host { get; set; } 40 | public string QueueName { get; set; } 41 | public string Username { get; set; } 42 | public string Password { get; set; } 43 | } 44 | 45 | public class RabbitMQPublisher : IRabbitMQPublisher 46 | { 47 | private readonly IModel _channel; 48 | private readonly RabbitMqOptions _options; 49 | 50 | public RabbitMQPublisher(IModel channel, IOptions options) 51 | { 52 | _channel = channel; 53 | _options = options.Value; 54 | } 55 | 56 | public Task Publish(string message, 57 | string? subject = null, 58 | string? eventType = null, 59 | string? dataVersion = null) 60 | { 61 | return Task.Run(() => 62 | { 63 | _channel.QueueDeclare(queue: _options.QueueName, durable: false, exclusive: false, autoDelete: false, arguments: null); 64 | var body = Encoding.UTF8.GetBytes(message); 65 | _channel.BasicPublish(exchange: "", routingKey: _options.QueueName, basicProperties: null, body: body); 66 | }); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /InPoint/InPoint.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | png-transparent-molecule-molecular-biology-computer-icons-others-biology-chemistry-dna-thumbnail.ico 8 | True 9 | JOEVER MONCEDA 10 | The InPoint NuGet library simplifies the integration of multiple messaging providers in .NET applications. 11 | It enables developers to configure and use various messaging systems—such as RabbitMQ, Event Hub, Service Bus, 12 | and Event Grid—without the complexities of handling each provider separately. 13 | 2024 14 | png-transparent-molecule-molecular-biology-computer-icons-others-biology-chemistry-dna-thumbnail.png 15 | https://github.com/Ethan0007/InPoint 16 | GIT 17 | NuGet ; Messaging; EventHub; RabbitMQ; ServiceBus; EventGrid 18 | https://github.com/Ethan0007/InPoint 19 | README.md 20 | InPoint 21 | False 22 | true 23 | True 24 | True 25 | License.txt 26 | 1.0.1 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | True 36 | \ 37 | 38 | 39 | True 40 | \ 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | all 57 | runtime; build; native; contentfiles; analyzers; buildtransitive 58 | 59 | 60 | 61 | 62 | 63 | PreserveNewest 64 | True 65 | \ 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # InPoint - Distributed Messaging Architecture 2 | ### _NuGet Library: Simplifying Messaging Providers in .NET_ 3 | [![NuGet Downloads](https://img.shields.io/nuget/dt/InPoint.svg)](https://github.com/Ethan0007/InPoint) 4 | [![NuGet Version](https://img.shields.io/nuget/v/InPoint.svg)](https://github.com/Ethan0007/InPoint) 5 | ```dotnet add package InPoint --version 1.0.1``` 6 | 7 | [![PubSub](https://github.com/Ethan0007/InPoint/blob/main/publish-subscribe.png?raw=true)](https://github.com/Ethan0007/InPoint/blob/main/publish-subscribe.png) 8 | 9 | #### Introduction 10 | In today's microservices architecture, messaging systems play a crucial role in ensuring seamless communication between services. However, managing multiple messaging providers can be a daunting task. This article addresses a common challenge developers face when integrating various messaging systems in .NET applications and provides a clear solution to streamline this process using the InPoint NuGet library. 11 | 12 | #### The Problem 13 | When working with multiple messaging providers like RabbitMQ, Event Hub, Service Bus, and Event Grid, developers often run into configuration issues, especially when the required providers are not specified in the configuration file. This oversight can lead to runtime errors, making it challenging to maintain and extend your application. 14 | 15 | To avoid such pitfalls, it’s essential to ensure that your application is configured correctly to recognize and utilize the specified messaging providers. 16 | 17 | #### The Solution: InPoint NuGet Library 18 | To effectively manage different messaging providers, we can create a modular setup in .NET that allows for easy configuration and integration of various messaging systems. The InPoint NuGet library provides a straightforward way to achieve this, allowing you to register multiple messaging providers easily. 19 | 20 | #### Libraries to Install 21 | To implement this solution, you will need to install the following libraries: 22 | - dotnet add package RabbitMQ.Client 23 | - dotnet add package Microsoft.Azure.EventHubs 24 | - dotnet add package Microsoft.Azure.ServiceBus 25 | - dotnet add package Microsoft.Azure.EventGrid 26 | 27 | #### JSON Configuration 28 | Here's an example of the appsettings.json file that outlines the configuration for multiple messaging providers: 29 | ``` 30 | { 31 | "MessagingProvider": [ "RabbitMQ", "EventHub", "ServiceBus", "EventGrid" ], 32 | "RabbitMQ": { 33 | "Host": "localhost", 34 | "UserName": "guest", 35 | "Password": "guest" 36 | }, 37 | "EventHub": { 38 | "ConnectionString": "YourEventHubConnectionString", 39 | "EventHubName": "YourEventHubName" 40 | }, 41 | "ServiceBus": { 42 | "ConnectionString": "YourServiceBusConnectionString", 43 | "QueueName": "YourQueueName" 44 | }, 45 | "EventGrid": { 46 | "TopicEndpoint": "https://yourtopic.westeurope-1.eventgrid.azure.net/api/events", 47 | "SasKey": "YourSasKey" 48 | } 49 | } 50 | ``` 51 | 52 | 53 | #### Using the InPoint Library in Your Application 54 | ##### Step 1: Register the InPoint Library 55 | In your Program.cs file, you can register the InPoint messaging services with the following line: 56 | ``` 57 | builder.Services.AddInPointMessaging(builder.Configuration); 58 | ``` 59 | This will configure your application to utilize the specified messaging providers. 60 | ##### Step 2: Implement Messaging in Your Controller 61 | Here’s how to implement a controller that uses the messaging service to publish messages: 62 | 63 | ``` 64 | [ApiController] 65 | [Route("api/[controller]")] 66 | public class MessageController : ControllerBase 67 | { 68 | private readonly InPointPublisherFactory _publisherFactory; 69 | private readonly IConfiguration _configuration; 70 | 71 | public MessageController(InPointPublisherFactory publisherFactory, IConfiguration configuration) 72 | { 73 | _publisherFactory = publisherFactory; 74 | _configuration = configuration; 75 | } 76 | 77 | [HttpPost("publish")] 78 | public async Task PublishMessage([FromBody] string message) 79 | { 80 | var providers = _configuration.GetSection("MessagingProvider").Get(); 81 | var selectedProvider = providers.First(); // Choose the provider logic here 82 | 83 | var publisher = _publisherFactory.GetPublisher(selectedProvider); 84 | await publisher.Publish(message); 85 | 86 | return Ok("Message published successfully!"); 87 | } 88 | } 89 | ``` 90 | ##### Step 3: Implement a Notification Service 91 | You can also create a service that utilizes the messaging system to send notifications: 92 | ``` 93 | public class NotificationService 94 | { 95 | private readonly InPointPublisherFactory _publisherFactory; 96 | private readonly IConfiguration _configuration; 97 | 98 | public NotificationService(InPointPublisherFactory publisherFactory, IConfiguration configuration) 99 | { 100 | _publisherFactory = publisherFactory; 101 | _configuration = configuration; 102 | } 103 | 104 | public async Task SendNotification(string message) 105 | { 106 | var providers = _configuration.GetSection("MessagingProvider").Get(); 107 | var selectedProvider = providers.First(); // Choose the provider logic here 108 | 109 | var publisher = _publisherFactory.GetPublisher(selectedProvider); 110 | await publisher.Publish(message); 111 | } 112 | } 113 | ``` 114 | 115 | #### Additional Resources 116 | - [RabbitMQ Documentation](https://www.rabbitmq.com/) 117 | - [Azure Event Hubs Documentation](https://azure.microsoft.com/en-us/products/event-hubs) 118 | - [Azure Service Bus Documentation](https://azure.microsoft.com/en-us/products/service-bus/?ef_id=_k_Cj0KCQjwsc24BhDPARIsAFXqAB3E5BjZWmnkqTID22quT_mEgNOILfymHDd0CKXqV9seMModR1JyOvQaAkvSEALw_wcB_k_&OCID=AIDcmm76som1hh_SEM__k_Cj0KCQjwsc24BhDPARIsAFXqAB3E5BjZWmnkqTID22quT_mEgNOILfymHDd0CKXqV9seMModR1JyOvQaAkvSEALw_wcB_k_&gad_source=1&gclid=Cj0KCQjwsc24BhDPARIsAFXqAB3E5BjZWmnkqTID22quT_mEgNOILfymHDd0CKXqV9seMModR1JyOvQaAkvSEALw_wcB) 119 | - [Azure Event Grid Documentation](https://learn.microsoft.com/en-us/azure/event-grid/overview) 120 | 121 | #### License 122 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 123 | Copyright (c) 2024 [Joever Monceda](https://github.com/Ethan0007) 124 | 125 | Linkedin: [Joever Monceda](https://www.linkedin.com/in/joever-monceda-55242779/) 126 | Medium: [Joever Monceda](https://medium.com/@joever.monceda/new-net-core-vuejs-vuex-router-webpack-starter-kit-e94b6fdb7481) 127 | Twitter [@_EthanHunt07](https://twitter.com/_EthanHunt07) 128 | Facebook: [Ethan Hunt](https://www.facebook.com/nethan.hound.3/) 129 | --------------------------------------------------------------------------------