<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akalanka Gajasinghe</title>
    <description>The latest articles on DEV Community by Akalanka Gajasinghe (@angajasinghe).</description>
    <link>https://dev.to/angajasinghe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F551626%2F218d0ac4-55ed-49eb-9fc6-b7d2848c7dcc.jpeg</url>
      <title>DEV Community: Akalanka Gajasinghe</title>
      <link>https://dev.to/angajasinghe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/angajasinghe"/>
    <language>en</language>
    <item>
      <title>Azure Service Bus</title>
      <dc:creator>Akalanka Gajasinghe</dc:creator>
      <pubDate>Sat, 16 Mar 2024 13:18:05 +0000</pubDate>
      <link>https://dev.to/angajasinghe/azure-service-bus-1mgp</link>
      <guid>https://dev.to/angajasinghe/azure-service-bus-1mgp</guid>
      <description>&lt;p&gt;Azure Service Bus is a cloud-based messaging service that facilitates communication between applications and services without requiring everything to be in the cloud. At its core is the Azure Service Bus Namespace, which serves as a container for organizing messaging components. Within a single namespace, you can have multiple queues and topics, helping to manage and streamline communication.&lt;/p&gt;

&lt;p&gt;Service Bus is ideal for enterprise-level messaging where critical business information, such as invoices, financial transactions, or credit card swipes, needs to be reliably transmitted. Its key features ensure that messages are,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;delivered in sequence &lt;/li&gt;
&lt;li&gt;maintain integrity during sessions&lt;/li&gt;
&lt;li&gt;support transactional operations, &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;making it crucial for operations where accuracy and order are paramount.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi0g6o5b84q8m1ktghiej.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi0g6o5b84q8m1ktghiej.png" alt="azure service bus" width="624" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Azure Service Bus offers comprehensive integration with various Azure services, enhancing its functionality and application scope. Key services that integrate well with Service Bus include Event Grid, Logic Apps, Functions, Dynamics 365, and Stream Analytics. The integration with Event Grid, in particular, enables connectivity with numerous other services, expanding its utility. Moreover, Service Bus provides a straightforward API, facilitating easy interaction with these diverse Azure services&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Queue&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Messages are sent to and received from queues, simplifying the communication process.&lt;/li&gt;
&lt;li&gt;Queues allow for the temporary storage of messages until the receiving application is available to process them.&lt;/li&gt;
&lt;li&gt;Messages in the queue are organized and timestamped upon arrival, ensuring an orderly sequence.&lt;/li&gt;
&lt;li&gt;Once a message is accepted, it is stored in redundant storage to prevent loss.&lt;/li&gt;
&lt;li&gt;The delivery mechanism is based on pull mode, requiring the receiving application to request messages actively.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7y4m6u014ah8chzwdla4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7y4m6u014ah8chzwdla4.png" alt="Queue processing" width="487" height="85"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Topics and Subscriptions&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Topics and Subscriptions are used for asynchronous message sending and receiving, similar to queues but with distinct capabilities.&lt;/li&gt;
&lt;li&gt;While queues support point-to-point communication, topics are ideal for publish/subscribe (pub/sub) scenarios.&lt;/li&gt;
&lt;li&gt;A single topic can have multiple, independent subscriptions, enhancing message distribution flexibility.&lt;/li&gt;
&lt;li&gt;Subscribers can receive all messages sent to a topic or use rules and filters to receive specific messages, allowing targeted communication.&lt;/li&gt;
&lt;li&gt;Topics enable distributing a single message to multiple receivers, which is not typically possible with queues.&lt;/li&gt;
&lt;li&gt;Azure Service Bus incorporates various advanced features, demonstrating its robustness as a messaging technology.&lt;/li&gt;
&lt;li&gt;It integrates seamlessly with other Azure services, extending its utility and application within the Azure ecosystem.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2wym04t34qqd31z4oapm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2wym04t34qqd31z4oapm.png" alt="Topics and Subscriptions processing" width="476" height="163"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Azure Service Bus and Azure Storage Queues&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Azure Storage Queues are very similar to Azure Service Bus, Comparison is down below.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Feature&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Azure Service Bus&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Azure Storage Queues&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Intended Use&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Complex enterprise-level messaging&lt;/td&gt;
&lt;td&gt;Simple, high-volume messaging&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Messaging Features&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Advanced (e.g., dead-lettering, duplicate detection, sessions, transactions)&lt;/td&gt;
&lt;td&gt;Basic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Communication Patterns&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Supports various patterns (e.g., pub/sub, sessions)&lt;/td&gt;
&lt;td&gt;Basic queuing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Integration&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Extensive with Azure services&lt;/td&gt;
&lt;td&gt;Limited&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Protocols and Standards&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;AMQP, SBMP, HTTP/HTTPS&lt;/td&gt;
&lt;td&gt;HTTP/HTTPS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Security&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Advanced security and compliance&lt;/td&gt;
&lt;td&gt;Basic security&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Scalability&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Highly scalable with more complex features&lt;/td&gt;
&lt;td&gt;Highly scalable with simpler features&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Message Size and TTL&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Up to 256 KB/message, configurable TTL&lt;/td&gt;
&lt;td&gt;Up to 64 KB (256 KB for premium), max 7 days TTL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cost&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Up to 256 KB/message, configurable TTL&lt;/td&gt;
&lt;td&gt;More cost-effective for basic needs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Ideal for&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Enterprise applications requiring reliable, ordered, and complex messaging&lt;/td&gt;
&lt;td&gt;Web-scale applications requiring massive volume processing with less complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Azure Service Bus supports various messaging patterns that allow the distribution of messages to multiple consumers. Some of these patterns include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Publish/Subscribe (Pub/Sub):&lt;/strong&gt; 

&lt;ul&gt;
&lt;li&gt;This is the primary pattern used to distribute a message to multiple consumers. A publisher sends messages to a topic, and each message is then forwarded to all subscriptions associated with that topic. Each subscription acts like an independent queue, receiving copies of the messages sent to the topic. This way, multiple consumers (subscribers) can independently retrieve and process the messages.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Competing Consumers&lt;/strong&gt;: 

&lt;ul&gt;
&lt;li&gt;In this pattern, multiple consumers connect to the same queue or subscription. Each consumer competes for message processing. Once a consumer retrieves a message for processing, it is locked and becomes invisible to other consumers. This pattern is useful for load balancing and increasing throughput, as different consumers process different messages in parallel.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Forwarding&lt;/strong&gt;: 

&lt;ul&gt;
&lt;li&gt;Azure Service Bus allows you to automatically forward messages from a queue or subscription to another queue or topic. This feature can be used to create complex routing schemes or workflows where messages processed by one consumer are automatically sent to another queue or topic for further processing by additional consumers.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sessions&lt;/strong&gt;: 

&lt;ul&gt;
&lt;li&gt;When dealing with ordered message processing, sessions allow related messages to be processed sequentially. In a scenario with multiple consumers, each session (identified by a session ID) ensures that all messages within a session are processed by the same consumer, maintaining message order within each session.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dead-lettering:&lt;/strong&gt; 

&lt;ul&gt;
&lt;li&gt;While not a direct method of distributing messages to multiple consumers, dead-letter queues can be used as part of a broader pattern where messages that cannot be processed (e.g., due to format errors or processing failures) are moved to a dead-letter queue. These messages can then be consumed and handled (e.g., investigated or reprocessed) by a separate set of consumers.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>cloud</category>
      <category>azure</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Simplify Component Communication in .NET with MediatR</title>
      <dc:creator>Akalanka Gajasinghe</dc:creator>
      <pubDate>Mon, 03 Jul 2023 18:54:46 +0000</pubDate>
      <link>https://dev.to/angajasinghe/simplify-component-communication-in-net-with-mediatr-5dk0</link>
      <guid>https://dev.to/angajasinghe/simplify-component-communication-in-net-with-mediatr-5dk0</guid>
      <description>&lt;p&gt;MediatR, the acclaimed NuGet package, is a game-changer for .NET development, revolutionizing the way we handle communication and achieve loose coupling between components. Let's explore the key features of MediatR in this LinkedIn post:&lt;/p&gt;

&lt;p&gt;🔹 Mediator Pattern Made Easy:&lt;/p&gt;

&lt;p&gt;MediatR provides a robust implementation of the mediator pattern for .NET, enabling seamless communication and decoupling between components. Say goodbye to rigid dependencies and welcome scalable and maintainable applications.&lt;/p&gt;

&lt;p&gt;🔹 Request/Response Messages:&lt;/p&gt;

&lt;p&gt;With MediatR, you can dispatch request/response messages effortlessly. These messages are directed to a single handler responsible for processing them. This approach streamlines your codebase and promotes a clear separation of concerns, enhancing the overall maintainability and testability of your application.&lt;/p&gt;

&lt;p&gt;🔹 Notification Messages:&lt;/p&gt;

&lt;p&gt;MediatR takes it a step further by enabling the dispatching of notification messages. These messages are distributed to multiple handlers, allowing you to implement publish/subscribe or observer patterns within your application. This flexibility empowers you to build highly extensible and event-driven systems.&lt;/p&gt;

&lt;p&gt;By leveraging MediatR in your .NET projects, you unlock the following benefits:&lt;/p&gt;

&lt;p&gt;✅ Simplified communication and reduced coupling between components.&lt;/p&gt;

&lt;p&gt;✅ Clean separation of concerns, resulting in highly maintainable code.&lt;/p&gt;

&lt;p&gt;✅ Improved testability with easy mocking and unit testing of individual handlers.&lt;/p&gt;

&lt;p&gt;✅ Enhanced extensibility through the publish/subscribe mechanism for notification messages.&lt;/p&gt;

&lt;p&gt;Join the growing community of developers embracing MediatR and revolutionize your application architecture today!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Inject MediatR to your DI container
services.AddMediatR(cfg =&amp;gt; {
    cfg.RegisterServicesFromAssembly(typeof(Program).Assembly);
});

// Request/response messages
public class CreateTodoItemCommand : IRequest&amp;lt;int&amp;gt; { }
public class CreateTodoItemCommandHandler : IRequestHandler&amp;lt;CreateTodoItemCommand, int&amp;gt;
{
    public Task&amp;lt;int&amp;gt; Handle(CreateTodoItemCommandrequest, CancellationToken cancellationToken)
    {
        // Your application logic
       return Task.FromResult(0);
    }
}

// Notification messages
public class TodoItemCompletedEvent: INotification { } 

public class TodoItemCompletedEventHandler : INotificationHandler&amp;lt;TodoItemCompletedEvent&amp;gt;
{
    public Task Handle(TodoItemCompletedEvent notification, CancellationToken cancellationToken)
    {
        // Your application logic
        return Task.CompletedTask;
    }
}

public class TodoItemCompletedSendMailEventHandler : INotificationHandler&amp;lt;TodoItemCompletedEvent&amp;gt;
{
    public Task Handle(TodoItemCompletedEvent notification, CancellationToken cancellationToken)
    {
        // Your application logic
        return Task.CompletedTask;
    }
}

// Let's Call
// private ISender _mediator;
_mediator.Send(new CreateTodoItemCommand())

// private IPublisher _publisher;
_publisher.Publish(new TodoItemCompletedEvent());

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>programming</category>
      <category>dotnet</category>
      <category>cleancode</category>
      <category>csharp</category>
    </item>
  </channel>
</rss>
