Exemple #1
0
        public void BasicConsume(string queue, IBasicConsumer consumer)
        {
            var msg = new AdministrationMessage(MessageType.Subscribe, queue);

            _comm.SendAdministrationMessage(msg);
            consumers.Add(new Tuple <IBasicConsumer, string>(consumer, queue));
        }
Exemple #2
0
 public void StartTimeSync(List <BrokerInformation> brokersToSync)
 {
     //Todo: send clock sync receivedMessage T1 to brokers
     foreach (var brokerInformation in brokersToSync)
     {
         _udpCommunication.SendAdministrationMessage(new AdministrationMessage
         {
             Type = MessageType.ClockSync,
             Data = MessagePackSerializer.Serialize(new ClockSyncMessage
             {
                 Type      = SyncType.SyncMessage,
                 TimeStamp = ElapsedTimeSpan()
             })
         }, brokerInformation.Ipaddress, brokerInformation.Port);
     }
 }
Exemple #3
0
        private void SendAntiEntropyMessage()
        {
            foreach (var broker in _brokers.Where(x => x.Active))
            {
                var numberOfBytesUsed       = 0;
                var tentativeMessagesToSend = _antiEntropy.GetTentativeMessagesToSendForNonPrimaryBroker(ref numberOfBytesUsed, _currentAntiEntropyRound);

                // + 1 because LastCommittedSeqNumberReceived represent the last received, and that number of message should not be resend
                var comittedMessagesToSend = _antiEntropy.GetCommittedMessagesToSend(ref numberOfBytesUsed, broker.LastCommittedSeqNumberReceived + 1);
                if (comittedMessagesToSend.Any())
                {
                    broker.LastCommittedSeqNumberReceived = comittedMessagesToSend.Last().Packet.GlobalSequenceNumber.Value;
                }

                broker.AntiEntropyRoundScheduledTaskIdAnswer = Guid.NewGuid();
                Console.WriteLine("Committed Messages " + comittedMessagesToSend.Count);
                Console.WriteLine("Tentative Messages " + tentativeMessagesToSend.Count);

                var administrationMessage = new AdministrationMessage(MessageType.AntiEntropy, MessagePackSerializer.Serialize(new AntiEntropyMessage
                {
                    PrimaryNumber             = _jsonConfigurator.GetSettings().PrimaryNumber,
                    Tentative                 = tentativeMessagesToSend,
                    Committed                 = comittedMessagesToSend,
                    Publishers                = _antiEntropy.GetPublishers(),
                    Subscribers               = _antiEntropy.GetSubscribers(),
                    AntiEntropyRound          = _currentAntiEntropyRound,
                    Primary                   = _isPrimary ? _jsonConfigurator.GetSettings().PrimaryNumber : 0,
                    AntiEntropyGarbageCollect = _currentAntiEntropyRound % 3 == 0 // GC every third round
                }));
                _udpCommunication.SendAdministrationMessage(administrationMessage, broker.Ipadress, broker.Port);
                Console.WriteLine("Time: " + _clock.ElapsedTimeSpan());
                //TODO: activate this later on
                //_schedular.ScheduleTask(Setup.Settings.AntiEntropyMilliseonds, broker.AntiEntropyRoundScheduledTaskIdAnswer, () =>
                //{
                //    broker.DeactivateBroker();
                //    //Todo: Broadcast to subs/pubs/brokers that a broker is down
                //});
            }
        }