当前位置: 首页>>代码示例>>C#>>正文


C# NetMQMessage.AppendEmptyFrame方法代码示例

本文整理汇总了C#中NetMQMessage.AppendEmptyFrame方法的典型用法代码示例。如果您正苦于以下问题:C# NetMQMessage.AppendEmptyFrame方法的具体用法?C# NetMQMessage.AppendEmptyFrame怎么用?C# NetMQMessage.AppendEmptyFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetMQMessage的用法示例。


在下文中一共展示了NetMQMessage.AppendEmptyFrame方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Send

		public Task Send(ArraySegment<byte> data, params object[] connectionIDs)
		{
			var task = new Task(() =>
			{
				var msg = new NetMQMessage();
				if (_socket is RouterSocket)
				{
					msg.Append(new byte[0]);
					msg.AppendEmptyFrame();
				}
				msg.Append(data.Count == data.Array.Length ? data.Array : data.ToArray());

				if (connectionIDs.Length <= 0)
					_socket.SendMultipartMessage(msg);
				else
				{
					foreach (var connection in connectionIDs)
					{
						if (_socket is RouterSocket && connection is byte[])
						{
							msg.Pop();
							msg.Push(((byte[])connection));
						}
						_socket.SendMultipartMessage(msg);
					}
				}
			});
			task.Start(_scheduler);
			return task;
		}
开发者ID:BrannonKing,项目名称:Kts.Remoting,代码行数:30,代码来源:NetMQSocketTransportSource.cs

示例2: Handle

        public void Handle(NetMQFrame[] sender, NetMQMessage message)
        {
            Logger.Debug("[Queue_SubscribeHandler] Received subscribe request.");

            var requestId = message.Pop();
            var context = message.Pop().ConvertToString();
            var queueId = message.Pop().ConvertToString();
            var subscriberId = message.Pop().ConvertToString();
            var filter = message.Pop().ConvertToString();
            var utcStartTime = message.PopDateTime();
            var allocationSize = message.PopInt32();
            var allocationTimeInMilliseconds = message.PopInt32();

            var subscribe = new SubscribeToQueue(context,
                queueId,
                subscriberId,
                filter,
                utcStartTime, allocationSize, allocationTimeInMilliseconds);

            var queuedEvents = _storage.Subscribe(subscribe);
            var events = queuedEvents.Events;

            var msg = new NetMQMessage();
            msg.Append(sender);
            msg.AppendEmptyFrame();
            msg.Append(ResProtocol.ResClient01);
            msg.Append(requestId);
            msg.Append(ResCommands.QueuedEvents);
            msg.Append(context);
            msg.Append(queueId);
            msg.Append(subscriberId);
            msg.Append(DateTime.UtcNow.ToNetMqFrame());
            msg.Append(queuedEvents.AllocationId.ToNetMqFrame());

            var count = events.Length;
            msg.Append(count.ToNetMqFrame());

            foreach (var e in events)
            {
                msg.Append(e.EventId.ToByteArray());
                msg.Append(e.Stream);
                msg.Append(e.Context);
                msg.Append(e.Sequence.ToNetMqFrame());
                msg.Append(e.Timestamp.ToNetMqFrame());
                msg.Append(e.TypeKey);
                msg.Append(e.Headers.ToNetMqFrame());
                msg.Append(e.Body);
            }

            var result = new QueuedMessagesFetched(msg);
            while (!_outBuffer.Offer(result))
                _spin.SpinOnce();
        }
开发者ID:heartysoft,项目名称:res,代码行数:53,代码来源:SubscribeHandler.cs

示例3: Send

        public Action<NetMQMessage> Send(NetMQSocket socket, PendingResRequest pendingRequest, Guid requestId)
        {
            var pending = (PendingResRequest<QueryEventsForStreamResponse>) pendingRequest;
            var msg = new NetMQMessage();
            msg.AppendEmptyFrame();
            msg.Append(ResProtocol.ResClient01);
            msg.Append(ResCommands.QueryEventsByStream);
            msg.Append(requestId.ToByteArray());
            msg.Append(_context);
            msg.Append(_stream);
            msg.Append(_fromVersion.ToNetMqFrame());
            msg.Append(_maxVersion.ToNetMqFrame());

            socket.SendMultipartMessage(msg);

            return m =>
            {
                var command = m.Pop().ConvertToString();

                if (command == ResCommands.Error)
                {
                    var errorCode = m.Pop().ConvertToString();
                    var errorDetails = m.Pop().ConvertToString();
                    ErrorResolver.RaiseException(errorCode, errorDetails, pending.SetException);
                    return;
                }

                if (command != ResCommands.QueryEventsByStreamResponse)
                    pending.SetException(new UnsupportedCommandException(command));

                var count = m.PopInt32();

                var events = new EventInStorage[count];

                for (var i = 0; i < count; i++)
                {
                    var id = new Guid(m.Pop().ToByteArray());
                    var streamId = m.Pop().ConvertToString();
                    var context = m.Pop().ConvertToString();
                    var sequence = m.PopInt64();
                    var timestamp = m.PopDateTime();;
                    var type = m.PopString();
                    var headers = m.PopStringOrNull();
                    var body = m.PopString();

                    events[i] = new EventInStorage(context, streamId, sequence, type, id, headers, body, timestamp);
                }

                var result = new QueryEventsForStreamResponse(_context, _stream, events);
                pending.SetResult(result);
            };
        }
开发者ID:heartysoft,项目名称:res,代码行数:52,代码来源:QueryEventsForStreamRequest.cs

示例4: EmptyFrames

        public void EmptyFrames()
        {
            var message = new NetMQMessage();

            message.Append("middle");
            message.AppendEmptyFrame();
            message.PushEmptyFrame();

            Assert.AreEqual("middle", message[1].ConvertToString());
            Assert.AreEqual(0, message[0].MessageSize);
            Assert.AreEqual(0, message[2].MessageSize);
            Assert.AreEqual(3, message.FrameCount);
        }
开发者ID:ezhuo,项目名称:netmq,代码行数:13,代码来源:MessageTests.cs

示例5: Run

        public void Run()
        {
            using (NetMQContext ctx = NetMQContext.Create())
            {
                using (var server = ctx.CreateRouterSocket())
                {
                    server.Bind("tcp://127.0.0.1:5556");

                    CreateClient(ctx, "A_");
                    CreateClient(ctx, "B_");
                    CreateClient(ctx, "C_");
                    CreateClient(ctx, "D_");

                    while (true)
                    {

                        var clientMessage = server.ReceiveMessage();
                        Console.WriteLine("========================");
                        Console.WriteLine(" INCOMING CLIENT MESSAGE ");
                        Console.WriteLine("========================");
                        for (int i = 0; i < clientMessage.FrameCount; i++)
                        {
                            Console.WriteLine("Frame[{0}] = {1}", i,
                                clientMessage[i].ConvertToString());
                        }

                        var clientAddress = clientMessage[0];
                        var clientOriginalMessage = clientMessage[2].ConvertToString();
                        string response = string.Format("{0} back from server",
                            clientOriginalMessage);

                        // "B_" client is special
                        if (clientOriginalMessage.StartsWith("B_"))
                        {
                            response = string.Format(
                                "special Message for 'B' back from server");
                        }

                        var messageToClient = new NetMQMessage();
                        messageToClient.Append(clientAddress);
                        messageToClient.AppendEmptyFrame();
                        messageToClient.Append(response);
                        server.SendMessage(messageToClient);
                    }
                }
            }

            Console.ReadLine();
        }
开发者ID:huoxudong125,项目名称:ZeroMqDemos,代码行数:49,代码来源:Program.cs

示例6: ProcessMessage

        public void ProcessMessage(NetMQMessage message, NetMQSocket socket)
        {
            var sender = new List<NetMQFrame>(message.FrameCount);

            for (int i = 0; i < message.FrameCount; i++)
            {
                var frame = message[i];
                if (frame.BufferSize == 0)
                    break;

                sender.Add(frame);
            }

            var protocolFrame = message[sender.Count + 1];
            var commandFrame = message[sender.Count + 2];
            var requestId = message[sender.Count + 3];

            try
            {
                _processor.ProcessMessage(message, socket);
            }
            catch (Exception e)
            {
                Log.Warn("[EHMessageProcessor] Error processing message.", e);
                var entry = _errorResolver.GetError(e);

                if (entry != null)
                {
                    var msg = new NetMQMessage();

                    foreach (var frame in sender)
                    {
                        msg.Append(frame);
                    }

                    msg.AppendEmptyFrame();

                    msg.Append(protocolFrame);
                    msg.Append(requestId);
                    msg.Append(ResCommands.Error);
                    msg.Append(entry.ErrorCode.ToString(CultureInfo.InvariantCulture));
                    msg.Append(entry.Message);
                    socket.SendMultipartMessage(msg);
                }
            }
        }
开发者ID:heartysoft,项目名称:res,代码行数:46,代码来源:ErrorHandlingMessageProcessor.cs

示例7: StartProcessingAsync

        public override async Task StartProcessingAsync(CancellationToken ct)
        {
            await Task.Run(() =>
            {
                int qId = 0;
                while (!ct.IsCancellationRequested)
                {
                    using (var ms = new MemoryStream())
                    {
                        var dt = _responseSocket.ReceiveMultipartMessage();
                        _logger.Trace("Worker {0} received", Id);
                        ms.Write(dt[0].ToByteArray(), 0, dt[0].MessageSize);
                        ms.Position = 0;
                        var data = (List<Frame>) _formatter.Deserialize(ms);
                        foreach (var frame in data)
                        {
                            ProcessFunction(frame.Data);

                            qId = frame.QueueId;
                        }
                        _logger.Trace("Worker {0} {1} fr processed", Id, qId);
                        StatisticsCollector.TaskProcessed(this);
                    }

                    if (Id == 3)
                    {
                        while (true)
                        {

                        }
                    }

                    using (var ms = new MemoryStream())
                    {
                        _formatter.Serialize(ms, new ProcessedEventArgs(qId));
                        var mqMessage = new NetMQMessage();
                        mqMessage.AppendEmptyFrame();
                        mqMessage.Append(ms.ToArray());
                        _responseSocket.SendMultipartMessage(mqMessage);
                        _logger.Trace("Worker {0} sended", Id);
                    }

                }
            }, ct);
        }
开发者ID:buldo,项目名称:MQExperiments,代码行数:45,代码来源:AsyncWorker.cs

示例8: Send

        public Action<NetMQMessage> Send(NetMQSocket socket, PendingResRequest pendingRequest, Guid requestId)
        {
            var pending = (PendingResRequest<CommitResponse>) pendingRequest;

            var msg = new NetMQMessage();
            msg.AppendEmptyFrame();
            msg.Append(ResProtocol.ResClient01);
            msg.Append(ResCommands.AppendCommit);
            msg.Append(requestId.ToByteArray());
            msg.Append(Context);
            msg.Append(Stream);
            msg.Append(ExpectedVersion.ToNetMqFrame());
            msg.Append(Events.Length.ToNetMqFrame());

            foreach (var e in Events)
            {
                msg.Append(e.EventId.ToByteArray());
                msg.Append(e.Timestamp.ToNetMqFrame());
                msg.Append(e.TypeTag);
                msg.Append(e.Headers.ToNetMqFrame());
                msg.Append(e.Body);
            }

            socket.SendMultipartMessage(msg);

            return m =>
            {
                var command = m.Pop().ConvertToString();

                if (command == ResCommands.Error)
                {
                    var errorCode = m.Pop().ConvertToString();
                    var errorDetails = m.Pop().ConvertToString();
                    ErrorResolver.RaiseException(errorCode, errorDetails, pending.SetException);
                    return;
                }

                if (command != ResCommands.CommitResult)
                    pending.SetException(new UnsupportedCommandException(command));

                var commitId = new Guid(m.Pop().ToByteArray());
                var result = new CommitResponse(commitId);
                pending.SetResult(result);
            };
        }
开发者ID:heartysoft,项目名称:res,代码行数:45,代码来源:CommitRequest.cs

示例9: Handle

        public void Handle(NetMQFrame[] sender, NetMQMessage message)
        {
            Logger.Debug("[Query_LoadEventsByStream] Received a request.");

            var requestId = message.Pop();
            var context = message.Pop().ConvertToString();
            var stream = message.Pop().ConvertToString();

            var fromVersion = message.PopInt64();

            var maxVersion = message.PopNullableInt64();

            var events = _storage.LoadEventsForStream(context, stream, fromVersion, maxVersion);

            var msg = new NetMQMessage();
            msg.Append(sender);
            msg.AppendEmptyFrame();
            msg.Append(ResProtocol.ResClient01);
            msg.Append(requestId);
            msg.Append(ResCommands.QueryEventsByStreamResponse);

            var count = events.Length;

            msg.Append(count.ToNetMqFrame());

            foreach (var e in events)
            {
                msg.Append(e.EventId.ToByteArray());
                msg.Append(e.Stream);
                msg.Append(e.Context);
                msg.Append(e.Sequence.ToNetMqFrame());
                msg.Append(e.Timestamp.ToNetMqFrame());
                msg.Append(e.TypeKey);
                msg.Append(e.Headers.ToNetMqFrame());
                msg.Append(e.Body);
            }

            var result = new QueryEventsForStreamLoaded(msg);
            while (!_buffer.Offer(result))
                _spin.SpinOnce();
        }
开发者ID:heartysoft,项目名称:res,代码行数:41,代码来源:LoadEventsByStreamHandler.cs

示例10: Process

        public void Process(IEnumerable<Frame> frames)
        {
            try
            {
                using (var ms = new MemoryStream())
                {
                    _formatter.Serialize(ms, frames.ToList());
                    ms.Position = 0;
                    var mqMessage = new NetMQMessage();
                    mqMessage.AppendEmptyFrame();
                    mqMessage.Append(ms.ToArray());
                    _socket.SendMultipartMessage(mqMessage);
                    _logger.Trace("Sended {0}q", frames.FirstOrDefault()?.QueueId ?? 0);
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
开发者ID:buldo,项目名称:MQExperiments,代码行数:21,代码来源:AsyncBrocker.cs

示例11: Send

        public void Send(NetMQSocket socket)
        {
            var msg = new NetMQMessage();
            msg.Append(_context.Sender);
            msg.AppendEmptyFrame();
            msg.Append(_protocol);
            msg.Append(_context.RequestId);

            if (_error == null)
            {
                msg.Append(ResCommands.CommitResult);
                msg.Append(_context.CommitId.ToByteArray());
            }
            else
            {
                msg.Append(ResCommands.Error);
                msg.Append(_error.ErrorCode.ToString(CultureInfo.InvariantCulture));
                msg.Append(_error.Message);
            }

            socket.SendMultipartMessage(msg);
        }
开发者ID:heartysoft,项目名称:res,代码行数:22,代码来源:CommitResult.cs

示例12: RouterAction

        private void RouterAction()
        {
            using (NetMQContext ctx = NetMQContext.Create())
            {
                using (RouterSocket socket = ctx.CreateRouterSocket())
                {
                    socket.Bind(Address);

                    while (true)
                    {
                        NetMQMessage message = socket.ReceiveMessage();
                        string topic = message.Last.ConvertToString();
                        byte[] snapshot = _snapshotFactory(topic);

                        var response = new NetMQMessage();
                        response.Append(message.First);
                        response.AppendEmptyFrame();
                        response.Append(snapshot);

                        socket.SendMessage(response);
                    }
                }
            }
        }
开发者ID:AlonAmsalem,项目名称:ServiceBlocks,代码行数:24,代码来源:NetMqSnapshotServer.cs

示例13: Receive

        /// <summary>
        /// Retrieves a RequestTask that combines the request Message and an Action to return the response
        /// </summary>
        /// <returns></returns>
        public RequestTask Receive()
        {
            try
            {
				var requestMessage = routerSocket.ReceiveMessage();
				var clientAddress = requestMessage[0];
				byte[] data = requestMessage[2].ToByteArray();

                var message = binarySerializer.Deserialize<Message>(data);
                Action<Message> reply = m => {
					var responseMessage = new NetMQMessage();
					responseMessage.Append(clientAddress);
					responseMessage.AppendEmptyFrame();
					responseMessage.Append(binarySerializer.Serialize<Message>(m));
					routerSocket.SendMessage(responseMessage);
				};

                return new RequestTask(message, reply);
            }
            catch (TerminatingException)
            {
                return default(RequestTask);
            }
        }
开发者ID:yonglehou,项目名称:Smoke,代码行数:28,代码来源:NetMQReceiver.cs

示例14: Send

        /// <summary>
        /// Sends a request message to the connected server and returns the response message, serializing and deserializing the
        /// request and response for network transport along the way
        /// </summary>
        /// <param name="message">Request message</param>
        /// <returns>Response message</returns>
        public Message Send(Message message)
        {
			var requestMessage = new NetMQMessage();
			requestMessage.AppendEmptyFrame();
			requestMessage.Append(binarySerializer.Serialize<Message>(message));

            dealerSocket.SendMessage(requestMessage);

			var responseMessage = dealerSocket.ReceiveMessage();

			if (responseMessage != null && responseMessage.FrameCount > 0)
			{
				byte[] returnData = responseMessage[1].ToByteArray();
				return binarySerializer.Deserialize<Message>(returnData);
			}
			else
				throw new InvalidOperationException("Response message in incorrect format");
        }
开发者ID:yonglehou,项目名称:Smoke,代码行数:24,代码来源:NetMQSender.cs

示例15: Send

        public Action<NetMQMessage> Send(NetMQSocket socket, PendingResRequest pendingRequest, Guid requestId)
        {
            var pending = (PendingResRequest<QueuedEventsResponse>) pendingRequest;

            var msg = new NetMQMessage();
            msg.AppendEmptyFrame();
            msg.Append(ResProtocol.ResClient01);
            msg.Append(ResCommands.AcknowledgeQueue);
            msg.Append(requestId.ToByteArray());

            msg.Append(_context);
            msg.Append(_queueId);
            msg.Append(_subscriberId);
            msg.Append(_allocationId.ToNetMqFrame());
            msg.Append(_allocationBatchSize.ToNetMqFrame());
            msg.Append(_allocationTimeoutInMilliseconds.ToNetMqFrame());

            socket.SendMultipartMessage(msg);

            return m =>
            {
                var command = m.Pop().ConvertToString();

                if (command == ResCommands.Error)
                {
                    var errorCode = m.Pop().ConvertToString();
                    var errorDetails = m.Pop().ConvertToString();
                    ErrorResolver.RaiseException(errorCode, errorDetails, pending.SetException);
                    return;
                }

                if (command != ResCommands.QueuedEvents)
                    pending.SetException(new UnsupportedCommandException(command));

                var queueContext = m.Pop().ConvertToString();
                var queueId = m.Pop().ConvertToString();
                var subscriberId = m.Pop().ConvertToString();
                var time = m.PopDateTime();
                var allocationId = m.PopNullableInt64();
                var count = m.PopInt32();

                var events = new EventInStorage[count];

                for (var i = 0; i < count; i++)
                {
                    var id = new Guid(m.Pop().ToByteArray());
                    var streamId = m.Pop().ConvertToString();
                    var context = m.Pop().ConvertToString();
                    var sequence = m.PopInt64();
                    var timestamp = m.PopDateTime();
                    var type = m.PopString();
                    var headers = m.PopStringOrNull();
                    var body = m.PopString();

                    events[i] = new EventInStorage(context, streamId, sequence, type, id, headers, body, timestamp);
                }

                var result = new QueuedEventsResponse(queueContext, queueId, subscriberId, time, allocationId, events);
                pending.SetResult(result);
            };
        }
开发者ID:heartysoft,项目名称:res,代码行数:61,代码来源:AcknowledgeQueueAndFetchNextRequest.cs


注:本文中的NetMQMessage.AppendEmptyFrame方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。