azure-signalr
azure-signalr copied to clipboard
[Question] How to specify MessagePack settings using the management API
When using the management API - like
var serviceManager = new ServiceManagerBuilder().WithOptions(o =>
{
o.ConnectionString = signalRConfiguration.ConnectionString;
})
.Build();
how can I tell it which MessagePack settings to use?
I understand that it automatically activates the MessagePack protocol, but I require specific configuration for MessagePack, how can I do that?
Thanks, MR
In Persistent mode, we use ServiceProtocol to let server communicate with signalr service. In Transient mode, actually we send http request to call REST API. We don't use signalr hub protocol between server and signalr service.
Messagepack is already supported between service and client.
client <--> signalrService <-->server
I guess what you need to configure is on your client: https://docs.microsoft.com/en-us/aspnet/core/signalr/messagepackhubprotocol?view=aspnetcore-5.0#configure-messagepack-on-the-client
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.DependencyInjection;
var hubConnection = new HubConnectionBuilder()
.WithUrl("/chathub")
.AddMessagePackProtocol()
.Build();
Hi & thanks @wanlwanl ,
so, just to make sure I understand you correctly:
if I setup the serviceManager
with
var serviceManager = new ServiceManagerBuilder().WithOptions(o =>
{
o.ConnectionString = signalRConfiguration.ConnectionString;
})
.Build();
and then use it like this
await using var context =_serviceManager.CreateHubContextAsync(NotificationConstants.HubName);
await context.Clients.Group(groupName).SendCoreAsync(channel, arguments);
and on the client I add my messagepack settings into the .AddMessagePackProtocol()
call like this:
new HubConnectionBuilder()
.WithUrl(negotiateUrl, configureConnection)
.AddMessagePackProtocol(configureMessagePack).Build()
...
void configureMessagePack(MessagePackHubProtocolOptions options)
{
options.SerializerOptions = options.SerializerOptions.WithSecurity(MessagePackSecurity.UntrustedData)
.WithResolver(new MyCustomResolver());
}
then it should just work (TM)?
The server would talk to Azure SignalR via http rest, while communication between client and SignalR would observe the messagepack settings I add inside the .AddMessagePackProtocol()
call?
I see, you not only need to add AddMessagePackProtocol
, but also have custom options on it. We don't support it in Management SDK.
Is this something with any likelihood to change in the near future (let's define near as within the next 1-2months) or not?
alternatively, if, without doing any special configuration, with the default setup, I send a byte[]
, will this be sent over the wire in binary format (so the serialized size equals the length of the array) or will it be serialized to JSON (so the size would be many times the length of the array)?
No, we don't have a plan to change, since we also have a feature of upstream, when client send mesaage with special hub protocol, the signalr service cannot understand the special protocol. And we have no plan to support uploading it for now.
Thanks, Wanpeng Li
From: ModernRonin @.> Sent: Thursday, May 27, 2021 6:35:15 PM To: Azure/azure-signalr @.> Cc: Wanpeng Li @.>; Mention @.> Subject: Re: [Azure/azure-signalr] [Question] How to specify MessagePack settings using the management API (#1284)
Is this something with any likelihood to change in the near future (let's define near as within the next 1-2months) or not?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAzure%2Fazure-signalr%2Fissues%2F1284%23issuecomment-849525164&data=04%7C01%7CWanpeng.Li%40microsoft.com%7Cd14a222c29d540dcfc6208d920fb1e1d%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637577085191257489%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=LLLwiTuM6IimJ2vGYUEU%2BgfU8yuJMWDlu6UQJQdxxXo%3D&reserved=0, or unsubscribehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAJDW7OLONIFT3KDUIURBVF3TPYN6HANCNFSM45P7O2ZQ&data=04%7C01%7CWanpeng.Li%40microsoft.com%7Cd14a222c29d540dcfc6208d920fb1e1d%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637577085191257489%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=yW5RqKjtIJxCJQcS5Twui0ZA%2F7yJ3fTrUAkoK97yPYU%3D&reserved=0.
Signalr service will only count outbound message (message that is go out of signalr service) for the protocol of client. So you can add message pack protocol to your client to avoid increasing billing (serialized to JSON for your client).
From: ModernRonin @.> Sent: Thursday, May 27, 2021 6:42:13 PM To: Azure/azure-signalr @.> Cc: Wanpeng Li @.>; Mention @.> Subject: Re: [Azure/azure-signalr] [Question] How to specify MessagePack settings using the management API (#1284)
alternatively, if, without doing any special configuration, with the default setup, I send a byte[], will this be sent over the wire in binary format (so the serialized size equals the length of the array) or will it be serialized to JSON (so the size would be many times the length of the array)?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAzure%2Fazure-signalr%2Fissues%2F1284%23issuecomment-849529132&data=04%7C01%7CWanpeng.Li%40microsoft.com%7C2ce7d1f881b648686c3908d920fc1705%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637577089370606699%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=ktIQnrTs6RHVRz0%2FsCGUmuJ4SEetvxbnmrYsUdQqUbY%3D&reserved=0, or unsubscribehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAJDW7OMWYFBRXLTQ5BUAVDDTPYOYLANCNFSM45P7O2ZQ&data=04%7C01%7CWanpeng.Li%40microsoft.com%7C2ce7d1f881b648686c3908d920fc1705%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637577089370606699%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=b7smPVsoJ4JZaUYu8DV7FbuAyXD0znt%2F8zLg0ggIews%3D&reserved=0.
In default config, the management sdk calls rest api, which will serialize to json, but it will not impact the billing since it is inboind message. But it can be slower. Suggest to use Persistent mode in WithOptions(...), it will create a websocket to signalr service to.communicate later, and use messagepack protocol inside, it is faster than the default one (transient mode) https://github.com/Azure/azure-signalr/blob/dev/docs/management-sdk-guide.md#transport-type
Thanks, Wanpeng Li
From: Wanpeng Li @.> Sent: Thursday, May 27, 2021 7:27:53 PM To: Azure/azure-signalr @.>; Azure/azure-signalr @.> Cc: Mention @.> Subject: Re: [Azure/azure-signalr] [Question] How to specify MessagePack settings using the management API (#1284)
Signalr service will only count outbound message (message that is go out of signalr service) for the protocol of client. So you can add message pack protocol to your client to avoid increasing billing (serialized to JSON for your client).
From: ModernRonin @.> Sent: Thursday, May 27, 2021 6:42:13 PM To: Azure/azure-signalr @.> Cc: Wanpeng Li @.>; Mention @.> Subject: Re: [Azure/azure-signalr] [Question] How to specify MessagePack settings using the management API (#1284)
alternatively, if, without doing any special configuration, with the default setup, I send a byte[], will this be sent over the wire in binary format (so the serialized size equals the length of the array) or will it be serialized to JSON (so the size would be many times the length of the array)?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAzure%2Fazure-signalr%2Fissues%2F1284%23issuecomment-849529132&data=04%7C01%7CWanpeng.Li%40microsoft.com%7C2ce7d1f881b648686c3908d920fc1705%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637577089370606699%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=ktIQnrTs6RHVRz0%2FsCGUmuJ4SEetvxbnmrYsUdQqUbY%3D&reserved=0, or unsubscribehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAJDW7OMWYFBRXLTQ5BUAVDDTPYOYLANCNFSM45P7O2ZQ&data=04%7C01%7CWanpeng.Li%40microsoft.com%7C2ce7d1f881b648686c3908d920fc1705%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637577089370606699%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=b7smPVsoJ4JZaUYu8DV7FbuAyXD0znt%2F8zLg0ggIews%3D&reserved=0.
thank you, Wanpeng Li, I will look into that!
Now MessagePack is also supported in the persistent mode and you could customize the MessagePack serialization options. Please note that this might break things if you also have SignalR Functions trigger to receive your client invocations because SignalR trigger uses default MessagePack serialization options. You could update your SDK to the latest version and follow the guide here .