public void SendMessages(NotNullOrWhiteSpaceString topic, NotNullable<IEnumerable<NotNullOrWhiteSpaceString>> messages) { if (messages.Value.Count() == 1) SendMessage(topic, messages.Value.First()); else { _producerFactory.CreateProducer(topic).Produce<string>(messages.Value.Select(m => m.Value).ToList(), topic); } }
public IKafkaProducer CreateProducer(NotNullOrWhiteSpaceString topic) { if(!_producers.ContainsKey(topic)) { _producers.Add(topic, new KafkaProducer(_configuration, _serializer)); } return _producers[topic]; }
public NotNullable<IQuota> CreateQuota(NotNullOrWhiteSpaceString topic) { ITopicConfiguration config = _hostConfiguration.Topic(topic); if (config == null || config.Quota == null) return new TransparentQuota(); else if (config.Quota.NumberOfELements != default(int)) return new NumberOfElementsQuota((uint)config.Quota.NumberOfELements); else if (config.Quota.ElapsedMinutes != default(int)) return new ElapsedTimeQuota(new Minute(config.Quota.ElapsedMinutes)); else if (config.Quota.TimeRange != null) return new TimeRangeQuota(config.Quota.TimeRange); return new TransparentQuota(); }
public void When_a_message_is_sent_it_removes_the_message_from_the_repository() { var repository = new NotNullable<IIncommingMessageRepository>( Substitute.For<IIncommingMessageRepository>()); var serviceEvents = new ServiceEvents(); var sut = new MessageCleanerService(serviceEvents, repository); var message = new NotNullOrWhiteSpaceString(StringExtension.RandomString()); serviceEvents.SentIncommingMessage(message); repository.Value.Received(1).Delete(message); }
public void When_receives_a_message_notifies_it_has_persisted_it() { var repository = Substitute.For<IIncommingMessageRepository>(); var serviceEvents = Substitute.For<IServiceEvents>(); var sut = new IncommingMessageService(repository, serviceEvents); var message = new NotNullOrWhiteSpaceString(StringExtension.RandomString()); sut.NewMessage(message); serviceEvents.Received(1).SavedIncommingMessage(message); }
/// <summary> /// Allows to hook for a given topic /// </summary> /// <param name="topicName">The topic which want to be listened to</param> public void ListenToTopic(NotNullOrWhiteSpaceString topicName) { if(!_listeners.ContainsKey(topicName)) { var newListener = _listenerFactory.CreateInstance(topicName); newListener.StartListening(); newListener.ListenedMessages.Subscribe((message) => ManageListenedMessages(message, topicName)); _listeners.Add(topicName, newListener); } }
public MessageForwarder( NotNullOrWhiteSpaceString topic, NotNullable<IMomRepository> momRepository, NotNullable<IServiceEvents> mediator, NotNullable<IQuota> quota) { _topic = topic; _momRepository = momRepository.Value; _mediator = mediator.Value; _quota = quota.Value; }
/// <summary> /// Constructor /// </summary> /// <param name="eventID">The EventId of the message which was being processed</param> /// <param name="messageType">The MessageType of the message which was being processed</param> /// <param name="messageHandler">The Handler which tried to process the message</param> /// <param name="message">The exception message</param> /// <param name="exception">The catched exception</param> public ProcesedMessageException( Guid eventID, NotNullOrWhiteSpaceString messageType, NotNullOrWhiteSpaceString messageHandler, NotNullOrWhiteSpaceString message, NotNullable<Exception> exception) :base(message, exception) { EventID = eventID; MessageType = messageType; MessageHandler = messageHandler; }
public void When_a_message_is_removed_emits_serviceEvent_DeletedIncommingMessage() { var repository = new NotNullable<IIncommingMessageRepository>(Substitute.For<IIncommingMessageRepository>()); var serviceEvents = new ServiceEvents(); var sut = new MessageCleanerService(serviceEvents, repository); var message = new NotNullOrWhiteSpaceString(StringExtension.RandomString()); bool eventEmitted = false; serviceEvents.DeletedIncommingMessageSequence.Subscribe(new Action<NotNullOrWhiteSpaceString>(s => { Assert.Equal(message.Value, s.Value); eventEmitted = true; })); serviceEvents.SentIncommingMessage(message); Assert.True(eventEmitted); }
public IMessageForwarder CreateForwarder(NotNullOrWhiteSpaceString topic) { var fordwarder = _forwarders .Where(f => f.Topic.Equals(topic, StringComparison.OrdinalIgnoreCase)) .FirstOrDefault(); if(fordwarder == null) { fordwarder = new MessageForwarder( topic, new NotNullable<IMomRepository>(_momRepository), new NotNullable<IServiceEvents>(_mediator), _quotaFactory.CreateQuota(topic) ); _forwarders.Add(fordwarder); } return fordwarder; }
/// <summary> /// Deserializes a message and emit it to serviceEvents /// </summary> /// <param name="message">The message listened</param> /// <param name="topic">The topic in which the message was listened</param> void ManageListenedMessages(byte[] message, NotNullOrWhiteSpaceString topic) { BaseEvent @event = null; try { @event = _serializer.Deserialize<BaseEvent>(message); if(@event.IsValid()) { var incommingEvent = new IncommingEvent { @event = @event, RawData = message }; _serviceEvents.AddIncommingEvent(incommingEvent); } else { var receivedInvalidMessage = new ReceivedInvalidMessage { EventID = @event.EventID, MessageType = @event.MessageType, Topic = @event.Topic, InvalidReason = @event.InvalidReason.Value }; _serviceEvents.AddReceivedInvalidMessageEvent(receivedInvalidMessage); } } catch { var receivedInvalidMessage = new ReceivedInvalidMessage { InvalidReason = EInvalidMessageReason.Undeserializable, Topic = topic }; _serviceEvents.AddReceivedInvalidMessageEvent(receivedInvalidMessage); } }
public void NewMessage(NotNullOrWhiteSpaceString incommingMessage) { _repository.Save(incommingMessage); _hostMediator.SavedIncommingMessage(incommingMessage); }
public void SentIncommingMessage( NotNullOrWhiteSpaceString incommingMessage) { _sentIncommingMessageSequence.OnNext(incommingMessage); }
public IMessageForwarder CreateForwarder(NotNullOrWhiteSpaceString topic) { if (!Forwarders.ContainsKey(topic)) Forwarders.Add(topic, Substitute.For<IMessageForwarder>()); return Forwarders[topic]; }
public void DeletedIncommingMessage(NotNullOrWhiteSpaceString message) { _deletedIncommingMessageSequence.OnNext(message); }
public void SendMessage(NotNullOrWhiteSpaceString topic, NotNullOrWhiteSpaceString message) { _producerFactory.CreateProducer(topic).Produce<string>(message.Value, topic); }
void RemoveMessage(NotNullOrWhiteSpaceString mesage) { _repository.Delete(mesage); _serviceEvents.DeletedIncommingMessage(mesage); }
public void SendMessages(NotNullOrWhiteSpaceString topic, NotNullable<IEnumerable<NotNullOrWhiteSpaceString>> messages) { if (ReceivedSendMessages.ContainsKey(topic)) ReceivedSendMessages[topic].AddRange(messages.Value.Select(s => s.Value)); else ReceivedSendMessages.Add(topic, messages.Value.Select(s => s.Value).ToList()); }
public void Delete(NotNullOrWhiteSpaceString message) { var newContent = File.ReadAllLines("PendingMessages").ToList(); newContent.Remove(message); File.WriteAllLines("PendingMessages",newContent); }
public ITopicConfiguration Topic(NotNullOrWhiteSpaceString topic) { return Topics .Where(t=> t.TopicName.Equals(topic.Value, StringComparison.OrdinalIgnoreCase)) .FirstOrDefault(); }
public IKafkaProducer CreateProducer(NotNullOrWhiteSpaceString topic) { if (Producer == null) Producer = Substitute.For<IKafkaProducer>(); return Producer; }
public void Save(NotNullOrWhiteSpaceString message) { File.AppendAllLines("PendingMessages", new List<string> { message }); }