Exemple #1
0
        public void Run(CancellationToken token)
        {
            using (Socket processPullSocket = _context.CreateSocket(SocketType.PULL))
                using (Socket routerPushSocket = _context.CreateSocket(SocketType.PUSH))
                {
                    // Bind and connect to sockets
                    processPullSocket.Bind(_processPullAddress);
                    routerPushSocket.Connect(_routerPushAddress, token);

                    // Process while canellation not requested
                    while (!token.IsCancellationRequested)
                    {
                        // Waits for binary envelopes (with timeout)
                        var packet = processPullSocket.RecvPacket(200);
                        if (packet == null)
                        {
                            continue;
                        }

                        // Ignore packets without messages
                        if (packet.Headers.ContentType != ContentType.Messages)
                        {
                            continue;
                        }

                        foreach (var envelope in packet.Envelopes)
                        {
                            //Console.WriteLine("Envelope accepted : {0}. Now = {1}. Current: {2}, Previous: {3}", envelope.GetMessage().ToString(), DateTime.Now.Millisecond, packet.GetHeaders().CurrentJournalSequence, packet.GetHeaders().PreviousJournalSequence);
                        }

                        // Publish all messages
                        //PublishMessages(routerPushSocket, packet, 1);
                    }
                }
        }
Exemple #2
0
        public void Run(CancellationToken token)
        {
            Int64 previousJournalSeq = 0;
            Int64 currentJournalSeq  = 0;


            using (Socket routerRepSocket = _context.CreateSocket(SocketType.PULL))
                using (Socket routerPubSocket = _context.CreateSocket(SocketType.PUB))
                    using (Socket domainReqSocket = _context.CreateSocket(SocketType.PUSH))
                    {
                        // Bind and connect to sockets
                        routerRepSocket.Bind(_routerRepAddress);
                        routerPubSocket.Bind(_routerPubAddress);
                        domainReqSocket.Connect(_domainReqAddress, token);

                        // Process while canellation not requested
                        while (!token.IsCancellationRequested)
                        {
                            // Waits for binary envelopes (with timeout)
                            var packet = routerRepSocket.RecvPacket(200);
                            if (packet == null)
                            {
                                continue;
                            }

                            // Ignore packets without messages
                            if (packet.Headers.ContentType != ContentType.Messages)
                            {
                                continue;
                            }

                            previousJournalSeq = currentJournalSeq;

                            // Journal all messages
                            currentJournalSeq = JournalPacket(packet);

                            // Publish all messages
                            PublishMessages(routerPubSocket, packet, currentJournalSeq);

                            // Router to process node
                            Route(domainReqSocket, "process", packet.CloneEnvelopes(), currentJournalSeq, previousJournalSeq);
                        }
                    }
        }