Open Closed

SignalR in tiered project #7448


User avatar
0
IbrahimSarigoz created

Hi, I'm working on a SignalR project and I prefer not to use a distributed event bus. I've looked at ABP samples where one uses a distributed event bus and the other only relies on the web layer. Is it feasible to implement SignalR in a distributed architecture without using an event bus?

  • ABP Framework version: v8.1.3
  • UI Type: MVC
  • Database System: EF Core (Oracle)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes tiered

16 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Yes, you can use SignalR for two-way communication.

  • User Avatar
    0
    IbrahimSarigoz created

    https://volosoft.com/blog/RealTime-Messaging-Distributed-Architecture-Abp-SingalR-RabbitMQ

    For example, I couldn't manage this without distributed event bus.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    This example combines distributed events and SignalR.

    You can use SignalR directly

  • User Avatar
    0
    IbrahimSarigoz created

    Do you have any example basic project ?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Yes,

    see: https://github.com/abpframework/abp-samples/tree/master/SignalRDemoBlazorUI

  • User Avatar
    0
    IbrahimSarigoz created

    Hi, I prepare a basic abp mvc project. this is github link: https://github.com/Ibrahimsrgz/BasicSignalRApp.git

    as you know in mvc we dont have access token provider and in this example i dont want to check access provider. so i changed api.host.module a bit.

    unfortuanaly i am getting

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    HI,

    we have an MVC example, too. https://github.com/abpframework/abp-samples/tree/master/SignalRTieredDemo

    this is github link: https://github.com/Ibrahimsrgz/BasicSignalRApp.git

    please private the repo, it's includes your lienAbpLicenseCode

  • User Avatar
    0
    IbrahimSarigoz created

    I know this MVC example. The thing is i need hub in the application layer. in this example it is in web layer.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    You can try

    /signalr-hubs/chat

  • User Avatar
    0
    IbrahimSarigoz created

    I also try it and it gives same error

  • User Avatar
    1
    liangshiwei created
    Support Team Fullstack Developer

    add me to the repo, i will check it

    my github username is realLiangshiwei

  • User Avatar
    0
    IbrahimSarigoz created

    Have you had a chance to review it?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    You add the ChatHub in the HttpAPI.Host project, the client(web) needs to connect to the HttpAPI.Host You used the wrong url

    See my commit: https://github.com/Ibrahimsrgz/BasicSignalRApp/compare/fix?expand=1

  • User Avatar
    0
    IbrahimSarigoz created

    Thanks a lot for your response and help. It works now when its allowed for anonymous

    in security part, i change hub.cs allowanonymous to Authorize and i am getting

    I pushed my repo.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    you need to pass the access_token

    for example:

    public class IndexModel : IndexModelBase
    {
        public string Token { get; set; }
        
        public IndexModel(IChatsAppService chatsAppService)
            : base(chatsAppService)
        {
        }
    
        public override async Task OnGetAsync()
        {
            Token = await HttpContext.GetTokenAsync("access_token");
        }
    }
    
    @section scripts
    {
        <script>
            var token = '@Model.Token';
        </script>
        <abp-script src="/Pages/Chats/index.js" />
        <abp-script type="typeof(SignalRBrowserScriptContributor)" />
    
    @*//<suite-custom-code-block-2>*@
    @*//</suite-custom-code-block-2>*@
    }
    
    var connection = new signalR.HubConnectionBuilder().withUrl("https://localhost:44367/signalr-hubs/chat?access_token="+token).build();
    

  • User Avatar
    0
    IbrahimSarigoz created

    Thank you, I get it.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11