Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I add ServerlessHub? #270

Open
danylo-dudok opened this issue Sep 6, 2021 · 1 comment
Open

How do I add ServerlessHub? #270

danylo-dudok opened this issue Sep 6, 2021 · 1 comment

Comments

@danylo-dudok
Copy link

danylo-dudok commented Sep 6, 2021

Trying to add multiple ServerlessHub in one azure function .NET 5 project.

Having "No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).".

    public class ChatHub : ServerlessHub
    {
        [FunctionName("negotiate")]
        public SignalRConnectionInfo Negotiate([HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequest req)
        {
            return Negotiate(req.Headers["x-ms-signalr-user-id"], GetClaims(req.Headers["Authorization"]));
        }

        [FunctionName(nameof(OnConnected))]
        public async Task OnConnected([SignalRTrigger]InvocationContext invocationContext, ILogger logger)
        {
            if (invocationContext.Claims.TryGetValue("id", out var groupName))
            {
                await Groups.AddToGroupAsync(invocationContext.ConnectionId, groupName);
                logger.LogInformation($"{invocationContext.ConnectionId} has connected");
            }
            else
            {
                logger.LogInformation($"{invocationContext.ConnectionId} does not have id claim");
            }
        }
        
        [FunctionName(nameof(OnDisconnected))]
        public async Task OnDisconnected([SignalRTrigger]InvocationContext invocationContext, ILogger logger)
        {
            if (invocationContext.Claims.TryGetValue("id", out var groupName))
            {
                await Groups.RemoveFromGroupAsync(invocationContext.ConnectionId, groupName);
                logger.LogInformation($"{invocationContext.ConnectionId} disconnected");
            }
            else
            {
                logger.LogInformation($"{invocationContext.ConnectionId} does not have id claim");
            }
        }
    }
@Y-Sindo
Copy link
Member

Y-Sindo commented Sep 9, 2021

.NET 5 function project has an isolated-process model, and you have to use the package Microsoft.Azure.Functions.Worker.Extensions.SignalRService. ServerlessHub is in Microsoft.Azure.WebJobs.Extensions.SignalRService package, so not supported in .NET 5 function project. We are investigating into how to provide a similar developing experience in isolated-process model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants