2
2
using System . Threading . Tasks ;
3
3
using MediatR ;
4
4
using Microsoft . AspNetCore . SignalR ;
5
+ using Microsoft . Extensions . Logging ;
5
6
using NetCoreKit . Infrastructure . Bus . Kafka ;
6
7
using Project . Proto ;
7
8
@@ -16,29 +17,43 @@ public class ProjectHostService : HostedService,
16
17
INotificationHandler < Notifications . TaskCreated >
17
18
{
18
19
private readonly IDispatchedEventBus _eventBus ;
20
+ private readonly ILogger < ProjectHostService > _logger ;
19
21
20
- public ProjectHostService ( IHubContext < ProjectHub > context , IDispatchedEventBus eventBus )
22
+ public ProjectHostService ( IHubContext < ProjectHub > context , IDispatchedEventBus eventBus , ILoggerFactory loggerFactory )
21
23
{
22
24
_eventBus = eventBus ;
23
25
Clients = context . Clients ;
26
+ _logger = loggerFactory . CreateLogger < ProjectHostService > ( ) ;
24
27
}
25
28
26
29
private IHubClients Clients { get ; }
27
30
28
31
public async Task Handle ( Notifications . ProjectCreated notification , CancellationToken cancellationToken )
29
32
{
33
+ _logger . LogInformation ( "Pushing message to projectCreatedNotify..." ) ;
30
34
await Clients . All . SendAsync ( "projectCreatedNotify" , notification , cancellationToken ) ;
31
35
}
32
36
33
37
public async Task Handle ( Notifications . TaskCreated notification , CancellationToken cancellationToken )
34
38
{
39
+ _logger . LogInformation ( "Pushing message to taskAddedToProjectNotify..." ) ;
35
40
await Clients . All . SendAsync ( "taskAddedToProjectNotify" , notification , cancellationToken ) ;
36
41
}
37
42
38
43
protected override Task ExecuteAsync ( CancellationToken cancellationToken )
39
44
{
40
- Task . Run ( ( ) => _eventBus . Subscribe < ProjectCreatedMsg > ( "project-created" ) , cancellationToken ) ;
41
- Task . Run ( ( ) => _eventBus . Subscribe < TaskCreatedMsg > ( "task-created" ) , cancellationToken ) ;
45
+ Task . Run ( ( ) =>
46
+ {
47
+ _logger . LogInformation ( "[NCK] Start to subscribe to project-created..." ) ;
48
+ return _eventBus . Subscribe < ProjectCreatedMsg > ( "project-created" ) ;
49
+ } , cancellationToken ) ;
50
+
51
+ Task . Run ( ( ) =>
52
+ {
53
+ _logger . LogInformation ( "[NCK] Start to subscribe to task-created..." ) ;
54
+ return _eventBus . Subscribe < TaskCreatedMsg > ( "task-created" ) ;
55
+ } , cancellationToken ) ;
56
+
42
57
return Task . CompletedTask ;
43
58
}
44
59
}
0 commit comments