Posted by Anuraj on Tuesday, September 4, 2018 Reading time :1 minute
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 :)
What do you think? I would like to hear your thoughts, suggestions, and questions in the comments section below.