예제 #1
0
        public void Subscribe(string topic, Action <MPSMessage> handler)
        {
            // Mock testing of subscription.
            for (int i = 1; i <= 1500; i++)
            {
                Trade T = new Trade();
                if (i % 3 == 1)
                {
                    T.Type = TradeType.EQ;
                }
                else if (i % 3 == 2)
                {
                    T.Type = TradeType.FX;
                }
                else
                {
                    T.Type = TradeType.Opt;
                }
                T.TradeID = i;

                TradeMessageHeader header = new TradeMessageHeader()
                {
                    MessageKey = i, MessageType = TradeMessageType.Added, SequenceNumber = i
                };

                MPSMessage message = new MPSMessage()
                {
                    Header = header, Payload = T
                };
                handler.Invoke(message);
            }
        }
예제 #2
0
        public void MPSMessageHander(MPSMessage message)
        {
            // pre-checks
            // Push message to the queue
            // Optional ACK. This would mean local resilience would be required for processing queue.
            TradeMessageHeader header = message.Header as TradeMessageHeader;
            ITrade             trade  = message.Payload as ITrade;

            if (header == null)
            {
                logger.Error($"Failed to parse message with header key: {message.Header.MessageKey}");
                return;
            }

            if (trade == null)
            {
                logger.Error($"Failed to parse message with header key: {header.MessageKey} and sequence no: {header.SequenceNumber}");
                return;
            }

            TradeMessage tradeMessage = new TradeMessage()
            {
                Header = header, Trade = trade
            };

            try
            {
                AddMessage(tradeMessage);
            }
            catch (Exception ex)
            {
                logger.Warn(ex, $"Error while adding message with sequence number {tradeMessage.Header.SequenceNumber} to queue. Retrying ...");
                if (!RetryHandler(AddMessage, tradeMessage))
                {
                    logger.Error($"Retries failed for sequence number : {tradeMessage.Header.SequenceNumber}");
                }
            }
        }