logo
Tags down

shadow

How to write an EasyNetQ auto subscriber dispatcher for the ASP.NET Core services provider?


By : ahojcek
Date : October 17 2020, 06:10 AM
I hope this helps you . So, the EasyNetQ auto subscriber has a basic default dispatcher that cannot create message consumer classes with non-parameterless constructors. , So, here's what I came up with.
code :
public class MessageDispatcher : IAutoSubscriberMessageDispatcher
{
    private readonly IServiceProvider provider;

    public MessageDispatcher(IServiceProvider provider)
    {
        this.provider = provider;
    }

    public void Dispatch<TMessage, TConsumer>(TMessage message)
        where TMessage : class
        where TConsumer : class, IConsume<TMessage>
    {
        using(var scope = provider.CreateScope())
        {
            var consumer = scope.ServiceProvider.GetRequiredService<TConsumer>();
            consumer.Consume(message);
        }
    }

    public async Task DispatchAsync<TMessage, TConsumer>(TMessage message)
        where TMessage : class
        where TConsumer : class, IConsumeAsync<TMessage>
    {
        using(var scope = provider.CreateScope())
        {
            var consumer = scope.ServiceProvider.GetRequiredService<TConsumer>();
            await consumer.ConsumeAsync(message);
        }
    }
}
public MessageDispatcher(IServiceProvider provider)
{
    this.provider = provider;
}
using(var scope = provider.CreateScope())
{
    var consumer = scope.ServiceProvider.GetRequiredService<TConsumer>();
    consumer.Consume(message);
}
public async Task DispatchAsync<TMessage, TConsumer>(TMessage message)
    where TMessage : class
    where TConsumer : class, IConsumeAsync<TMessage>
{
    using(var scope = provider.CreateScope())
    {
        var consumer = scope.ServiceProvider.GetRequiredService<TConsumer>();
        await consumer.ConsumeAsync(message);
    }
}
public void ConfigureServices(IServiceCollection services)
{
    // messaging
    services.AddSingleton<IBus>(RabbitHutch.CreateBus("host=localhost"));
    services.AddSingleton<MessageDispatcher>();
    services.AddSingleton<AutoSubscriber>(provider =>
    {
        var subscriber = new AutoSubscriber(provider.GetRequiredService<IBus>(), "example")
        {
            AutoSubscriberMessageDispatcher = provider.GetRequiredService<MessageDispatcher>();
        }
    });

    // message handlers
    services.AddScoped<ConsumeTextMessage>();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.ApplicationServices.GetRequiredServices<AutoSubscriber>().SubscribeAsync(Assembly.GetExecutingAssembly());
}


Share : facebook icon twitter icon

Provider and subscriber in SQL Server 2008, can subscriber handle insert/delete?


By : Nana Quarme Antwi-De
Date : March 29 2020, 07:55 AM
I wish this help you Based on the replication wizard of SSMS, it depends on your configuration:

EasyNetQ not calling subscriber


By : abdeddaim ahmed
Date : March 29 2020, 07:55 AM
this will help Each call to bus.Subscribe creates a new consumer. So the first time it works, you have just one consumer on your queue and when you publish a message to it it's routed to that consumer.
The second time you call bus.Subscribe a second consumer is bound to the same queue. When RabbitMQ has multiple consumers on a single queue it round-robins messages to the consumers. It's a feature. That's how it does work-sharing out-of-the-box. Your message is routed to the first consumer, not the consumer that you just declared. Same for the 3rd, 4th, etc consumers, so it appears that message has not arrived.

EasyNetQ with asp.net web api as subscriber


By : Tom Jerry
Date : March 29 2020, 07:55 AM
Hope this helps Generally RabbitMQ subscriptions don't work well with IIS hosted applications because you have no control over when the application is running. IIS will recycle, stop and start the app as it sees fit.
If you must do it, open the connection to RabbitMQ and start subscribing when the application starts, in Global.asax.cs for example, and make sure to dispose of everything properly when it closes.

Is it possible to write soap web services using .net core?


By : goath john
Date : March 29 2020, 07:55 AM
hop of those help? So the WCF client libraries have been ported to .net core but the server side libraries haven't as of the time of writing. There is this long running issue which is a request for the server side libraries to be ported over and Microsoft are saying it will happen, see this from a few weeks ago:

Turning a EasynetQ subscriber into an observable


By : HIREN CHANDANI
Date : March 29 2020, 07:55 AM
it fixes the issue I am using EasyNetQ as client library when using RabbitMQ. To create a subscriber one do like , Does this work?
code :
var observable = Observable.Create<MyMessage>(o => 
    bus.Subscribe<MyMessage>("my_subscription_id", msg => o.OnNext(msg))
);
Related Posts Related Posts :
  • Asp.Net Core Log Statements Not showing up in Application Insights
  • What replaces SynchronizationContext in ASP.NET Core?
  • Should I use Request-Id, X-Request-Id or X-Correlation-Id in the request header?
  • Azure AD B2C KMSI (Keep Me Signed In) does not keep me signed in
  • Sending a message to whatsapp groups through twilio with asp.net core
  • Is there any convention or built in concept how to inject a Json serializer?
  • Adding claims to IdentityServer setup by AddIdentityServer
  • Razor pages and webapi in the same project
  • ASP .NET Core webapi set cookie in middleware
  • Add custom fields for AspNetUser
  • How to create .razor files
  • ASP.NET Core 2.2 - accessing the StaticFileOption RequestPath later in code
  • Prevent Kestrel From Crashing When Port Is In Use
  • How can we integrate identityserver4 and web api in the same project(port) instead of creating different projects for ea
  • ASP.Net Core 2.2 Kubernetes Ingress
  • Bundling and Minification without using tools in ASP.NET MVC Core 2.2 web application
  • Using httpClient.postasync for web api calls .netcore
  • Which way to use HttpClientFactory is better?
  • Micro-service architecture in .NET Core: pattern or library for services to call each other
  • How to login a user with a JWT in asp.net core
  • Get String value from Enum in .net core Authorize Attribute
  • How to get host URL in the background service in asp .net core web api?
  • Registering multiple DbContext Instances on startup for use in Generic Repository
  • Kestrel address binding errors in azure app service
  • Razor Pages - Run a server side method NOT using post
  • Unable to reference a Blazor Component Library project
  • SwaggerUI not adding ApiKey to Header with Swashbuckle (5.x)
  • How to configure key settings for IdentityServer in appsettings.json for aspnet core app running on IIS
  • How to format the date using local culture using the blazor <InputDate /> tag
  • EF Core FromSql for same model but with different queries and extra columns
  • What is the difference between .Net Core installer vs .Net Core binaries?
  • Web API EF Core exceptions being swallowed?
  • _context.SaveChanges() works but await _context.SaveChangesAsync() doesn't
  • Azure, Error 403 - Forbidden: Client Certificate Required
  • Using IQueryable in onPost method
  • AspNetCore OData not working on .NET Core 3.0
  • Is there any way to block HTTP requests made by Postman in .NET Core?
  • Asp.net core 3.0 on Elastic Beanstalk
  • graceful shutdown asp.net core
  • Server response "unsupported media type" when I send JSON format data to Asp.net Core 3.0
  • service locater pattern vs service aggregate factory on inheritance
  • Unable to create swagger.json file when using aspnet-api-versioning
  • How to deserialize ProblemDetails in ASP.NET Core 2.2
  • How to use bind-value and bind-value:event on a custom component Blazor
  • Scaffolding Idenitiy in ASP.NET Core error
  • .Net Core on Raspberry Pi 4 with Raspbian?
  • ASP.NET Razor page, change color of particular row of table based on conditions?
  • Processing unhandled exceptions in ASP.NET Core 3.1
  • Validate jwt token from ASP.NET Core controller when not using Authorize attribute
  • How to use OData in a Asp.Net Core Razor Page Project (without MVC, API)
  • Can I conditionally add a hosted service based on options?
  • .NET core 3.1 app shows "Handler "aspNetCore" has a bad module "AspNetCoreModuleV2" in its modu
  • Problem with Bootstrap and bundle in ASP.NET Core
  • Referencing .NET Framework DLL from .Net Core 3
  • Proper way to update data in lookup tables with EFcore / ASP.net core? Do I do this in the seed method or another way?
  • extending IServiceCollection in asp net core
  • how to use async method inside lock
  • Nopcommerce Okta Integration
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk