-
Notifications
You must be signed in to change notification settings - Fork 748
Migrating to v4
NetMQ version 4 introduces some breaking changes for code migrated from version 3. These changes simplify the use of NetMQ, and the migration is not so difficult.
NetMQ version 3 will continue to receive bug fixes, but new features and improvements will be made to version 4 only. We expect most users will benefit from upgrading and encourage doing so.
- Make sure you take the latest release of the NetMQ 3 family from NuGet.
- Address any compiler warnings about usages of obsolete code. The compiler warnings will guide you regarding what changes are required.
- Uninstall the
NetMQ
NuGet package, and install theNetMQ4
package instead.
Much of the removed code have been marked [Obsolete]
for several releases now, so many of the changes shown here are unlikely to apply to your code. Further, any one application is unlikely to depend upon much of the public API of NetMQ. Don't let the length of this list concern you.
For completeness, all API changes are detailed here.
NetMQContext
has been removed. Previously you'd create one of these in your application and pass it around. NetMQ now manages this internally, making the API simpler.
Here's a comparison:
// NetMQ version 3
using (var context = NetMQContext.Create())
using (var publisher = context.CreatePublisherSocket())
{
// ...
}
// NetMQ version 4
using (var publisher = new PublisherSocket())
{
// ...
}
Note the factory methods for sockets no longer exist. Instead, just call the constructor of the type you want to use.
-
NetMQContext.CreateRequestSocket()
πnew RequestSocket()
-
NetMQContext.CreateResponseSocket()
πnew ResponseSocket()
-
NetMQContext.CreateDealerSocket()
πnew DealerSocket()
-
NetMQContext.CreateRouterSocket()
πnew RouterSocket()
-
NetMQContext.CreateXPublisherSocket()
πnew XPublisherSocket()
-
NetMQContext.CreatePairSocket()
πnew PairSocket()
-
NetMQContext.CreatePushSocket()
πnew PushSocket()
-
NetMQContext.CreatePublisherSocket()
πnew PublisherSocket()
-
NetMQContext.CreatePullSocket()
πnew PullSocket()
-
NetMQContext.CreateSubscriberSocket()
πnew SubscriberSocket()
-
NetMQContext.CreateXSubscriberSocket()
πnew XSubscriberSocket()
-
NetMQContext.CreateStreamSocket()
πnew StreamSocket()
-
NetMQContext.CreateMonitorSocket()
πnew MonitorSocket()
Further, constructors of the following classes no longer receive a context and calls should be updated:
NetMQForwarder
NetMQBeacon
QueueDevice
StreamerDevice
NetMQMonitor
These factory methods no longer accept context instances:
NetMQActor.Create
The Poller
and NetMQScheduler
classes have been merged into the new NetMQPoller
class.
-
Poller
πNetMQPoller
Adding and removing objects to poll:
-
Poller.AddSocket
πNetMQPoller.Add
-
Poller.AddTimer
πNetMQPoller.Add
-
Poller.AddPollInSocket
πNetMQPoller.Add
-
Poller.RemoveSocket
πNetMQPoller.Remove
-
Poller.RemoveTimer
πNetMQPoller.Remove
-
Poller.RemovePollInSocket
πNetMQPoller.Remove
Starting and stopping the poller.
-
Poller.PollTillCancelled
πNetMQPoller.Run
-
Poller.PollTillCancelledNonBlocking
πNetMQPoller.RunAsync
-
Poller.Cancel
πNetMQPoller.Stop
-
Poller.CancelNonBlocking
πNetMQPoller.StopAsync
Scheduling for the TPL:
-
NetMQScheduler
πNetMQPoller
By changing the Add*
names to all be the same as simply Add
, and by implementing IEnumerable
, NetMQPoller
now supports collection initialiser syntax:
new NetMQPoller { publisher, subscriber, timer, tcpSocket }
NetMQPoller
now implements ISynchronizeInvoke
(and continues extending TaskScheduler
), so it can be used to get schedule and synchronise work on the poller's thread from both the TPL and earlier BCL APIs.
Receiving a single frame using Msg
:
-
IReceivingSocket.Receive(ref Msg, SendReceiveOptions)
πReceive(ref Msg)
TryReceive(ref Msg, TimeSpan) : bool
Receiving a single frame as a byte[]
:
IReceivingSocket.Receive() : byte[]
IReceivingSocket.Receive(out bool) : byte[]
IReceivingSocket.Receive(bool, out bool) : byte[]
IReceivingSocket.Receive(SendReceiveOptions) : byte[]
IReceivingSocket.Receive(SendReceiveOptions, out bool) : byte[]
-
IReceivingSocket.Receive(TimeSpan) : byte[]
πReceiveFrameBytes(): byte[]
ReceiveFrameBytes(out bool): byte[]
TryReceiveFrameBytes(out byte[]) : bool
TryReceiveFrameBytes(out byte[], out bool) : bool
TryReceiveFrameBytes(TimeSpan, out byte[]) : bool
TryReceiveFrameBytes(TimeSpan, out byte[], out bool) : bool
Receiving an entire multipart message as List<byte[]>
:
IReceivingSocket.ReceiveMessages() : List<byte[]>(int)
-
IReceivingSocket.ReceiveAll() : List<byte[]>(int)
πIReceivingSocket.ReceiveMultipartBytes(int) : List<byte[]>
IReceivingSocket.ReceiveMultipartBytes(ref List<byte[]>, int): void
IReceivingSocket.TryReceiveMultipartBytes(ref List<byte[]>, int): bool
IReceivingSocket.TryReceiveMultipartBytes(TimeSpan, ref List<byte[]>, int): bool
Receiving a single frame as a string
:
IReceivingSocket.ReceiveString() : string
IReceivingSocket.ReceiveString(SendReceiveOptions) : string
IReceivingSocket.ReceiveString(SendReceiveOptions, out bool) : string
IReceivingSocket.ReceiveString(Encoding) : string
IReceivingSocket.ReceiveString(Encoding, SendReceiveOptions) : string
IReceivingSocket.ReceiveString(Encoding, SendReceiveOptions, out bool) : string
IReceivingSocket.ReceiveString(out bool) : string
IReceivingSocket.ReceiveString(bool, out bool) : string
IReceivingSocket.ReceiveString(TimeSpan) : string
IReceivingSocket.ReceiveString(Encoding, out bool) : string
IReceivingSocket.ReceiveString(Encoding, bool, out bool) : string
-
IReceivingSocket.ReceiveString(Encoding, TimeSpan) : string
πIReceivingSocket.ReceiveFrameString() : string
IReceivingSocket.ReceiveFrameString(out bool) : string
IReceivingSocket.ReceiveFrameString(Encoding) : string
IReceivingSocket.ReceiveFrameString(Encoding, out bool) : string
IReceivingSocket.TryReceiveFrameString(out string) : bool
IReceivingSocket.TryReceiveFrameString(out string, out bool) : bool
IReceivingSocket.TryReceiveFrameString(Encoding, out string) : bool
IReceivingSocket.TryReceiveFrameString(Encoding, out string, out bool) : bool
IReceivingSocket.TryReceiveFrameString(TimeSpan, out string) : bool
IReceivingSocket.TryReceiveFrameString(TimeSpan, out string, out bool) : bool
IReceivingSocket.TryReceiveFrameString(TimeSpan, Encoding, out string) : bool
IReceivingSocket.TryReceiveFrameString(TimeSpan, Encoding, out string, out bool) : bool
Receiving an entire multipart message as List<string>
:
IReceivingSocket.ReceiveStringMessages(int) : List<string>
IReceivingSocket.ReceiveStringMessages(Encoding, int) : List<string>
-
IReceivingSocket.ReceiveAllString() : List<string>
πIReceivingSocket.ReceiveMultipartStrings() : List<string>
IReceivingSocket.ReceiveMultipartStrings(out bool) : List<string>
IReceivingSocket.TryReceiveMultipartStrings(ref List<string>, int) : bool
IReceivingSocket.TryReceiveMultipartStrings(Encoding, ref List<string>, int) : bool
IReceivingSocket.TryReceiveMultipartStrings(TimeSpan, ref List<string>, int) : bool
IReceivingSocket.TryReceiveMultipartStrings(TimeSpan, Encoding, ref List<string>, int) : bool
Receiving an entire multipart message as NetMQMessage
:
IReceivingSocket.ReceiveMessage(bool) : NetMQMessage
IReceivingSocket.ReceiveMessage(NetMQMessage, bool) : void
-
IReceivingSocket.ReceiveMessage(TimeSpan) : NetMQMessage
πIReceivingSocket.ReceiveMultipartMessage(int) : NetMQMessage
IReceivingSocket.TryReceiveMultipartMessage(ref NetMQMessage, int): bool
IReceivingSocket.TryReceiveMultipartMessage(TimeSpan ref NetMQMessage, int): bool
Receiving a signal:
-
IReceivingSocket.WaitForSignal() : bool
πIReceivingSocket.ReceiveSignal(): bool
IReceivingSocket.TryReceiveSignal(out bool): bool
IReceivingSocket.TryReceiveSignal(TimeSpan, out bool): bool
The ability to skip a frame has been added:
IReceivingSocket.SkipFrame(): bool
IReceivingSocket.SkipFrame(out bool): bool
IReceivingSocket.TrySkipFrame(): bool
IReceivingSocket.TrySkipFrame(out bool): bool
IReceivingSocket.TrySkipFrame(TimeSpan): bool
IReceivingSocket.TrySkipFrame(TimeSpan, out bool): bool
As well as the ability to skip entire multipart messages, or the remainder of the current message when partially received:
-
IReceivingSocket.SkipMultipartMessage(): bool
-
IReceivingSocket.TrySkipMultipartMessage(): bool
-
IReceivingSocket.TrySkipMultipartMessage(TimeSpan): bool
-
NetMQSocketEventArgs.ReceiveReady
πNetMQSocketEventArgs.IsReadyToReceive
-
IOutgoingSocket.Send(ref Msg, SendReceiveOptions)
πSend(ref Msg, bool)
TrySend(ref Msg, TimeSpan, bool)
-
IOutgoingSocket.Send(byte[], int, SendReceiveOptions)
-
IOutgoingSocket.Send(byte[], int, bool, bool)
-
IOutgoingSocket.Send(byte[])
-
IOutgoingSocket.SendMore(byte[], bool)
-
IOutgoingSocket.SendMore(byte[], int, bool)
πSendFrame(byte[], bool)
SendFrame(byte[], int, bool)
SendMoreFrame(byte[])
SendMoreFrame(byte[], int)
TrySendFrame(TimeSpan, byte[], bool)
TrySendFrame(TimeSpan, byte[], int, bool)
TrySendFrame(byte[], bool)
TrySendFrame(byte[], int, bool)
-
IOutgoingSocket.Send(string, bool, bool)
-
IOutgoingSocket.Send(string, Encoding, SendReceiveOptions)
-
IOutgoingSocket.Send(string, Encoding, bool, bool)
-
IOutgoingSocket.SendMore(string, bool)
-
IOutgoingSocket.SendMore(string, Encoding, bool)
πSendFrame(string, bool)
SendMoreFrame(string)
TrySendFrame(TimeSpan, string, bool)
TrySendFrame(string, bool)
-
IOutgoingSocket.SendMessage(NetMQMessage, bool)
πSendMultipartMessage(NetMQMessage)
TrySendMultipartMessage(NetMQMessage)
TrySendMultipartMessage(TimeSpan, NetMQMessage)
-
NetMQSocketEventArgs.SendReady
πNetMQSocketEventArgs.IsReadyToSend
The Subscribe
and Unsubscribe
methods have been pushed down the class hierarchy from NetMQSocket
to only those subclasses to which subscription applies (SubscriberSocket
and XSubscriberSocket
). This shouldn't affect any correct code, but is mentioned here for completeness.
Some unused socket options were removed:
-
ReceiveTimeout
(use overloads ofTryReceive
that accept aTimeSpan
) -
SendTimeout
(use overloads ofTrySend
that accept aTimeSpan
) TcpAcceptFilter
TcpKeepaliveCnt
CopyMessages
-
ReceivevBuffer
πReceiveBuffer
(typo) -
GetLastEndpoint
πLastEndpoint
-
ErrorPollingException
was unused and has been removed -
AgainException
is no longer used as send/receive methods use theTry*
pattern and returnfalse
in case the operation would block
Unused members of the ErrorCode
enum have been removed.
-
ErrorCode.InProgres
πErrorCode.InProgress
(typo) -
ErrorCode.ENOENT
πErrorCode.EndpointNotFound
-
ErrorCode.EACCESS
πErrorCode.AccessDenied
-
ErrorCode.EFAULT
πErrorCode.Fault
-
ErrorCode.EINV
πErrorCode.Invalid
-
ErrorCode.EAGAIN
πErrorCode.TryAgain
-
ErrorCode.EINPROGRESS
πErrorCode.InProgress
-
ErrorCode.EPROTONOSUPPORT
πProtocolNotSupported.
-
ErrorCode.ENOTSUP
β -
ErrorCode.EADDRINUSE
πErrorCode.AddressAlreadyInUse
-
ErrorCode.EADDRNOTAVAIL
πErrorCode.AddressNotAvailable
-
ErrorCode.ENETDOWN
πErrorCode.NetworkDown
-
ErrorCode.ENOBUFS
πErrorCode.NoBufferSpaceAvailable
-
ErrorCode.EISCONN
β -
ErrorCode.EINTR
β -
ErrorCode.ENOTCONN
πErrorCode.NotConnected
-
ErrorCode.ECONNREFUSED
πErrorCode.ConnectionRefused
-
ErrorCode.EHOSTUNREACH
πErrorCode.HostUnreachable
-
ErrorCode.ZMQ_HAUSNUMERO
πErrorCode.BaseErrorNumber
-
ErrorCode.EMSGSIZE
πErrorCode.MessageSize
-
ErrorCode.EAFNOSUPPORT
πErrorCode.AddressFamilyNotSupported
-
ErrorCode.ENETUNREACH
πErrorCode.NetworkUnreachable
-
ErrorCode.ECONNABORTED
πErrorCode.ConnectionAborted
-
ErrorCode.ECONNRESET
πErrorCode.ConnectionReset
-
ErrorCode.ETIMEDOUT
πErrorCode.TimedOut
-
ErrorCode.ENETRESET
πErrorCode.NetworkReset
-
ErrorCode.EFSM
πErrorCode.FiniteStateMachine
-
ErrorCode.ENOCOMPATPROTO
β -
ErrorCode.ETERM
πErrorCode.ContextTerminated
-
ErrorCode.EMTHREAD
πErrorCode.EmptyThread
-
ErrorCode.EIOEXC
β -
ErrorCode.ESOCKET
β -
ErrorCode.EMFILE
πErrorCode.TooManyOpenSockets
The following items have been obsolete for a long time and their use is very unlikely if you observe compiler warnings. However they are listed here for completeness.
-
Blob
πNetMQFrame
-
Actor<T>
πNetMQActor
(non-generic) -
IShimHandler<T>
πIShimHandler
(non-generic) -
ActorKnownMessages.END_PIPE
πNetMQActor.EndShimMessage
- enum
MsgType.Invalid
πMsgType.Uninitialised
-
MsgType.Check()
πMsgType.IsInitialised
-
SocketEvent
πSocketEvents