Skip to content

Implementation of real time notification using ASP.NET Core Blazor, SignalR and PostgreSQL listen/notify feature + PgNotifyNet

Notifications You must be signed in to change notification settings

psosnicki/blazor-signalr-postgresql-realtime-notifications-example

Repository files navigation

Blazor + SignalR + pgNotifyNet + PostgresSQL notify/listen sample application

build

An implementation of real time notification using SignalR and PostgreSQL listen/notify feature + PgNotifyNet

Alt Text

cd docker-compose
docker-compose up
http://localhost:5111

Listen to database changes:

builder.Services.AddPgNotifyNet(builder.Configuration.GetConnectionString("SampleDatabase"),
                    c => 
                        c.Trigger(t => 
                            t.OnTable<Category>(table: "categories", schema: "public").After(Change.Update, Change.Insert)));

Handle notification from database and publish to clients via SignalR:

public class CategoryNotification : IHandleNotification<Category>
{
    private readonly IHubContext<DbNotificationHub> _hubContext;

    public CategoryNotification(IHubContext<DbNotificationHub> hubContext)
    {
        _hubContext = hubContext;
    }

    public Task OnDataChanged(Category oldData, Category newData, Change change)
    {
        _hubContext.Clients.All.SendAsync("onCategoryUpdated", oldData, newData, change);
        return Task.CompletedTask;
    }
}

Update client

@code{
        hubConnection.On<Category,Category, Change>("onCategoryUpdated", (oldCategory,newCategory,change) =>
        {
            ...
        });
    }

About

Implementation of real time notification using ASP.NET Core Blazor, SignalR and PostgreSQL listen/notify feature + PgNotifyNet

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published