September 04, 2018 by Anuraj
ASPNET Core SignalR MessagePack
This post is about using MessagePack protocol in SignalR. MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it’s faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves.
To use MessagePack, you need to install a nuget package -
Microsoft.AspNetCore.SignalR.Protocols.MessagePack. You can install the package using
dotnet add package Microsoft.AspNetCore.SignalR.Protocols.MessagePack --version 1.1.0-preview1-35029 command.
Once you install, you can modify the startup code like this.
npm install command to install the packages.
And you can modify the
_layout.cshtml file like this. Please note the order of script files is important. If signalr-protocol-msgpack.js is referenced before msgpack5.js, an error occurs when trying to connect with MessagePack. signalr.js is also required before signalr-protocol-msgpack.js.
To copy the files from
node_modules folder, I am using the MSBuild steps, like this.
You need to modify the script like this, to connect to MessagePack enabled SignalR hub.
Happy Programming :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub