Add routing
This commit is contained in:
parent
f8024b7205
commit
aef4be1ef9
@ -7,6 +7,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="Telegram">
|
||||
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
|
||||
<PackageVersion Include="Nocr.TelegramListener.Async.Api.Contracts" Version="1.0.0" />
|
||||
<PackageVersion Include="WTelegramClient" Version="3.7.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Label="Rebus">
|
||||
|
||||
@ -28,9 +28,9 @@ public sealed class NewMessageHandler : INewMessageHandler
|
||||
switch (messageBase)
|
||||
{
|
||||
case Message m:
|
||||
if (!string.IsNullOrWhiteSpace(m.message))
|
||||
if (string.IsNullOrWhiteSpace(m.message))
|
||||
break;
|
||||
|
||||
|
||||
_logger.LogInformation("{From} in {Chat} > {MessageText}",
|
||||
m.from_id.Peer(_telegramRegistry.Users, _telegramRegistry.Chats) ?? m.post_author,
|
||||
m.peer_id.Peer(_telegramRegistry.Users, _telegramRegistry.Chats),
|
||||
@ -42,7 +42,7 @@ public sealed class NewMessageHandler : INewMessageHandler
|
||||
Text = m.message,
|
||||
OccuredDateTime = _dateProvider.UtcNow
|
||||
};
|
||||
await _bus.Publish(@event);
|
||||
await _bus.Advanced.Topics.Publish("nocr.telegram.listener", @event);
|
||||
break;
|
||||
case MessageService ms:
|
||||
_logger.LogInformation("{From} in {Chat} > [{Action}]",
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Nocr.TelegramListener.Core\Nocr.TelegramListener.Core.csproj" />
|
||||
<ProjectReference Include="..\Nocr.TelegramListener.Core\Nocr.TelegramListener.Core.csproj" PrivateAssets="All"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
namespace Nocr.TelegramListener.Core.Options;
|
||||
|
||||
public sealed class RebusRabbitMqOptions
|
||||
{
|
||||
public string ConnectionString { get; set; }
|
||||
|
||||
public string InputQueueName { get; set; }
|
||||
|
||||
public string DirectExchangeName { get; set; }
|
||||
|
||||
public string TopicsExchangeName { get; set; }
|
||||
}
|
||||
@ -12,7 +12,7 @@ public class HostBuilderFactory<TStartup> where TStartup : class
|
||||
if (!string.IsNullOrWhiteSpace(baseDirectory))
|
||||
configurationBuilder.SetBasePath(baseDirectory);
|
||||
|
||||
configurationBuilder.AddJsonFile("appsettings.protected.json", false);
|
||||
configurationBuilder.AddJsonFile("appsettings.protected.json", true);
|
||||
})
|
||||
.ConfigureWebHostDefaults(host => { host.UseStartup<TStartup>(); })
|
||||
.UseSerilog((ctx, logBuilder) =>
|
||||
|
||||
@ -2,6 +2,7 @@ using Microsoft.Extensions.Options;
|
||||
using Nocr.TelegramListener.AppServices;
|
||||
using Nocr.TelegramListener.Async.Api.Contracts.Events;
|
||||
using Nocr.TelegramListener.Core.Dates;
|
||||
using Nocr.TelegramListener.Core.Options;
|
||||
using Rebus.Config;
|
||||
using Rebus.Routing.TypeBased;
|
||||
using Rebus.Serialization.Json;
|
||||
@ -25,22 +26,18 @@ public class Startup
|
||||
services.Configure<RebusRabbitMqOptions>(Configuration.GetSection(nameof(RebusRabbitMqOptions)));
|
||||
services.AddRebus((builder, ctx) =>
|
||||
builder.Transport(t =>
|
||||
t.UseRabbitMq(ctx.GetRequiredService<IOptions<RebusRabbitMqOptions>>().Value.ConnectionString,
|
||||
ctx.GetRequiredService<IOptions<RebusRabbitMqOptions>>().Value.InputQueueName)
|
||||
{
|
||||
var rebusOptions = ctx.GetRequiredService<IOptions<RebusRabbitMqOptions>>().Value;
|
||||
t.UseRabbitMq(rebusOptions.ConnectionString, rebusOptions.InputQueueName)
|
||||
.DefaultQueueOptions(queue => queue.SetDurable(true))
|
||||
.ExchangeNames("nocr.direct", "nocr.topics"))
|
||||
.ExchangeNames(rebusOptions.DirectExchangeName, rebusOptions.TopicsExchangeName);
|
||||
})
|
||||
.Serialization(s => s.UseSystemTextJson())
|
||||
.Logging(l => l.Serilog()));
|
||||
.Logging(l => l.Serilog())
|
||||
.Routing(r => r.TypeBased()));
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
}
|
||||
|
||||
public sealed class RebusRabbitMqOptions
|
||||
{
|
||||
public string ConnectionString { get; set; }
|
||||
|
||||
public string InputQueueName { get; set; }
|
||||
}
|
||||
}
|
||||
@ -9,7 +9,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Label="Rebus">
|
||||
<PackageReference Include="Rebus" />
|
||||
<PackageReference Include="Rebus.ServiceProvider" />
|
||||
<PackageReference Include="Rebus.RabbitMq" />
|
||||
<PackageReference Include="Rebus.Serilog" />
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
}
|
||||
},
|
||||
"RebusRabbitMqOptions": {
|
||||
"InputQueueName": "nocr.telegram.listener.queue"
|
||||
"InputQueueName": "nocr.telegram.listener.queue",
|
||||
"DirectExchangeName": "nocr.direct",
|
||||
"TopicsExchangeName": "nocr.topics"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user