MCPcopy Create free account
hub / github.com/TryCatchLearn/Overflow / WolverineExtensions

Class WolverineExtensions

Common/WolverineExtensions.cs:15–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13namespace Common;
14
15public static class WolverineExtensions
16{
17 public static async Task UseWolverineWithRabbitMqAsync(
18 this IHostApplicationBuilder builder,
19 Action<WolverineOptions> configureMessaging)
20 {
21 var isEfDesignTime = AppDomain.CurrentDomain.FriendlyName.StartsWith("ef", StringComparison.OrdinalIgnoreCase);
22
23 if (!isEfDesignTime)
24 {
25 var retryPolicy = Policy
26 .Handle<BrokerUnreachableException>()
27 .Or<SocketException>()
28 .WaitAndRetryAsync(
29 retryCount: 5,
30 retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
31 (exception, timespan, retryCount, _) =>
32 {
33 Console.WriteLine(
34 $"[RabbitMQ Retry] Attempt {retryCount} failed. Retrying in {timespan.TotalSeconds:F0}s: {exception.Message}");
35 });
36
37 await retryPolicy.ExecuteAsync(async () =>
38 {
39 var endpoint = builder.Configuration.GetConnectionString("messaging") ??
40 throw new InvalidOperationException("cannot get messaging connection string");
41
42 var factory = new ConnectionFactory
43 {
44 Uri = new Uri(endpoint)
45 };
46 await using var connection = await factory.CreateConnectionAsync();
47 });
48 }
49
50 builder.Services.AddOpenTelemetry().WithTracing(traceProviderBuilder =>
51 {
52 traceProviderBuilder.SetResourceBuilder(ResourceBuilder.CreateDefault()
53 .AddService(builder.Environment.ApplicationName))
54 .AddSource("Wolverine");
55 });
56
57 builder.UseWolverine(opts =>
58 {
59 opts.UseRabbitMqUsingNamedConnection("messaging")
60 .AutoProvision()
61 .UseConventionalRouting(x =>
62 {
63 x.QueueNameForListener(t => $"{t.FullName}.{builder.Environment.ApplicationName}");
64 });
65
66 configureMessaging(opts);
67 });
68 }
69}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…