I am using Rebus and have seen some strange behavior.
I do expect that my application (Endpoint) would open only one Connection to the RabbitMQ Server and this connection will be used as a Singleton.
However I have seen that the number of connections from my end point to the server increases over time a thing that leads to RabbitMQ server to crash.
I would like to know if there is any way to limit the number of connections that the rebus endpoint can open to RabbitMQ server.
In the method public void ConfigureServices(IServiceCollection services) we have
services.AutoRegisterHandlersFromAssemblyOf<RegisterMemberEventHandler>();
services.AddRebus(configure => configure
.Logging(l => l.Serilog())
.Transport(t => t.UseRabbitMq($"amqp://{UserName}:{Password}#{HostName}:{PortNo}", $"{EndPointQueue}")
.ClientConnectionName("OMRSAPI")
)
.Options(o =>
{
o.SetNumberOfWorkers(NumberOfWorkers);//10
o.SetMaxParallelism(MaxParallelism);//20
o.HandleMessagesInsideTransactionScope();
o.Decorate<IErrorHandler>(c => {
var errorHandler = c.Get<IErrorHandler>();
var loggerFactory = c.Get<IRebusLoggerFactory>();
var bus = c.Get<IBus>();
var transport = c.Get<ITransport>();
return new ErrorMessageHandler(errorHandler, loggerFactory,settings,bus,transport);
});
o.SimpleRetryStrategy(maxDeliveryAttempts: 3, secondLevelRetriesEnabled: true);
})
.Timeouts(x => x.StoreInSqlServer(settings.ConnectionStrings.RebusContext, "Timeouts"))
.Routing(r => r.TypeBased()
.Map<VerifyNID>(EndPointQueue)
.Map<ErrorOccurred>(ErrorQueueName)
));
//Some Code was removed for the sake of clarity
Related
The following code works fine with my Azure SignalR Services (serverless mode) and I am able to receieve messages/events successfully.
var connection = new HubConnectionBuilder()
.WithUrl(connectionInfo.NegotiationUrl!, options =>
{
options.Headers.Add("x-ms-signalr-userid", "myuserid");
options.Headers.Add("x-functions-key", "mykey");
})
.WithAutomaticReconnect(new[] { TimeSpan.Zero, TimeSpan.Zero, TimeSpan.FromMilliseconds(5) })
.Build();
connection.Closed += excecption =>
{
return Task.CompletedTask;
};
connection.On("onMsg", (Action<object>)(message =>
{
Console.WriteLine(message)
}));
I referenced the .NET MessagePack NuGet package for SignalR and invoked .AddMessagePackProtocol() extension method in the hub connection builder per the code below but stop receiving messages from SignalR.
var connection = new HubConnectionBuilder()
.WithUrl(connectionInfo.NegotiationUrl!, options =>
{
options.Headers.Add("x-ms-signalr-userid", "myuserid");
options.Headers.Add("x-functions-key", "mykey");
})
.AddMessagePackProtocol()
.WithAutomaticReconnect(new[] { TimeSpan.Zero, TimeSpan.Zero, TimeSpan.FromMilliseconds(5) })
.Build();
Am I missing anything in this configuration? What is the right approach to solve this problem? I don't think if we need to do anything on Azure SignalR Service configuration to start getting messagePack packets.
I expect to receive the signalR messages when the message pack protocol is enabled.
The chosen Azure signalR service transport type is Persistent, and the messagePack protocol is not supported in this mode per this article.
I am having trouble connecting to rabbitMq on remote server to public ip using masstransit. Let's say ip is 000.000.0.00.
While starting an app the next error is shown
RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable
x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(config =>
{
var rabbitMqUri = new Uri("rabbitmq://000.000.0.00");
config.Host(rabbitMqUri, h =>
{
h.Username(configuration["RabbitMQ:UserName"]);
h.Password(configuration["RabbitMq:Password"]);
});
})
I am simply trying to implement the example from the following link i.e.
https://learn.microsoft.com/en-us/aspnet/core/tutorials/signalr-blazor?view=aspnetcore-3.1&tabs=visual-studio&pivots=server
when I run the application I happen to get the following error.
I also tried the following after doing the google search but couldn't resolve it.
HubConnection = new HubConnectionBuilder()
.WithUrl(NavigationManager.ToAbsoluteUri("/chathub"), configureHttpConnection =>
{
//configureHttpConnection.WebSocketConfiguration = (sockets) =>
//{
// sockets.RemoteCertificateValidationCallback += new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true;
});
//};
//configureHttpConnection.HttpMessageHandlerFactory = (x) => new HttpClientHandler
//{
// ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
//};
})
.Build();
Also I ensured that self signed certificate is available under Trusted Root Certification Authorities
This question already has an answer here:
How to connect Grpc (NuGet >2.33) client (.NET Framework) with Grpc.Asp.NetCore (NuGet >2.31) server (.NET 5.0) using HTTPS and my own certificate?
(1 answer)
Closed 2 years ago.
I get this exception on the client:
Grpc.Core.RpcException: 'Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"#1606620349.107000000","description":"Failed to pick subchannel","file":"T:\src\github\grpc\workspace_csharp_ext_windows_x86\src\core\ext\filters\client_channel\client_channel.cc","file_line":4166,"referenced_errors":[{"created":"#1606620349.107000000","description":"failed to connect to all addresses","file":"T:\src\github\grpc\workspace_csharp_ext_windows_x86\src\core\ext\filters\client_channel\lb_policy\pick_first\pick_first.cc","file_line":398,"grpc_status":14}]}")'
Client channel:
private Channel GetChannel()
{
return new Channel(
_settings.FileServiceUri
, CertificatePEM == null ? ChannelCredentials.Insecure :
new SslCredentials(
CertificatePEM
, new KeyCertificatePair(CertificatePEM, File.ReadAllText("Syrilium.FileUpdater.cer.key"))
)
, new[] {
new ChannelOption(ChannelOptions.MaxReceiveMessageLength,int.MaxValue),
new ChannelOption(ChannelOptions.MaxSendMessageLength,int.MaxValue),
}
);
}
Server config:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(kestrelOptions =>
{
var sslCertificate = LoadSSLCertificate();
kestrelOptions.ListenAnyIP(/*IPAddress.Parse("127.0.0.1"),*/ 5001
, listenOptions =>
{
listenOptions.UseHttps(
sslCertificate,
httpsOptions =>
{
//httpsOptions.SslProtocols = SslProtocols.Tls12;
httpsOptions.ClientCertificateMode = ClientCertificateMode.AllowCertificate;
httpsOptions.ClientCertificateValidation = (certificate, chain, errors) =>
{
return true /*certificate.Thumbprint.Equals(_clientThumbprint, StringComparison.OrdinalIgnoreCase)*/;
};
}
);
listenOptions.Protocols = HttpProtocols.Http2;
}
);
});
webBuilder.UseStartup<Startup>();
});
When I just remove
listenOptions.UseHttps...
on the server and use
ChannelCredentials.Insecure
on the client, it works.
How to make those two communicate with HTTPS and my own certificate? Just a simple example of both client and server that work on these newest versions of libraries.
I get a call to
httpsOptions.OnAuthenticate = (ctx, auth) => { };
on service but I don't know what, if anything useful I can do with it?
It fails on a handshake.
I write the solution here after the comments contained the solution as who reads the comments...
The issue is that .net 5.0 client is faster and the client can't connect as the server is not ready to accept connections. When developing Client and Server best to have 2 solutions with the shared projects so you can debug both at the same time using 2 instances of visual studio. YOu can open the same solution with several instances of VS however you will start running into different issues for example in the intermediate window and output window.
At one point Rebus supported Message Mutators. I can't seem to find them anymore in the Rebus source code. Were they renamed? Do they still exist?
Sample code:
Configure.With(senderAdapter)
.Transport(t => t.UseMsmq(SenderInputQueueName, "error"))
.Events(e =>
{
e.MessageMutators.Add(new EvilMutator("first"));
e.MessageMutators.Add(new EvilMutator("second"));
e.MessageMutators.Add(new EvilMutator("third"));
})
.CreateBus().Start();
"Rebus 2" (all versions of Rebus since 0.90.0) does not have message mutators, because it's super extensible, and adding something that mutates an incoming/outgoing message is pretty easy with the incoming/outgoing pipelines.
The pipelines follow the "Russian doll" model where each step is responsible for calling the rest of the pipeline.
Adding a new "mutator" step can be done like this – first, we create a step that is capable of mutating incoming/outgoing messages:
public class MyMutatorStep : IIncomingStep, IOutgoingStep
{
public async Task Process(OutgoingStepContext context, Func<Task> next)
{
// here we have the message
var message = context.Load<Message>();
// mutate (or, more like "cripple", actually 😉)
context.Save(new Message(headers: message.Headers, body: new object()));
await next();
}
public async Task Process(IncomingStepContext context, Func<Task> next)
{
// here we have the message again
var message = context.Load<Message>();
await next();
}
}
and then we decorate the pipeline, injecting the step before serialization/after deserialization respectively:
Configure.With(...)
.(...)
.Options(o => o.Decorate<IPipeline>(c => {
var pipeline = c.Get<IPipeline>();
var step = new MyMutatorStep();
return new PipelineStepInjector(pipeline)
.OnReceive(step, PipelineStepRelativePosition.After, typeof(DeserializeIncomingMessageStep))
.OnSend(step, PipelineStepRelativePosition.Before, typeof(SerializeOutgoingMessageStep));
}))
.Start();
In this example, I mutate the outgoing message by replacing the message body with new object(), which is probably not what you want 😉 but hopefully, you can get an idea of the possibilities.