public PulsarSourceActor(ClientConfigurationData client, ReaderConfigurationData <T> readerConfiguration, IActorRef clientActor, IActorRef lookup, IActorRef cnxPool, IActorRef generator, long fromOffset, long toOffset, bool isLive, ISchema <T> schema) { _scheduler = Context.System.Scheduler.Advanced; _toOffset = toOffset; _parent = Context.Parent; _lastEventMessageOffset = fromOffset; var topicName = TopicName.Get(readerConfiguration.TopicName); IActorRef stateA = Context.ActorOf(Props.Create(() => new ConsumerStateActor()), $"StateActor{Guid.NewGuid()}"); var subscription = "player-" + ConsumerName.Sha1Hex(Guid.NewGuid().ToString()).Substring(0, 10); if (!string.IsNullOrWhiteSpace(readerConfiguration.SubscriptionRolePrefix)) { subscription = readerConfiguration.SubscriptionRolePrefix + "-" + subscription; } ConsumerConfigurationData <T> consumerConfiguration = new ConsumerConfigurationData <T>(); consumerConfiguration.TopicNames.Add(readerConfiguration.TopicName); consumerConfiguration.SubscriptionName = subscription; consumerConfiguration.SubscriptionType = SubType.Exclusive; consumerConfiguration.SubscriptionMode = SubscriptionMode.NonDurable; consumerConfiguration.ReceiverQueueSize = readerConfiguration.ReceiverQueueSize; consumerConfiguration.ReadCompacted = readerConfiguration.ReadCompacted; consumerConfiguration.StartMessageId = readerConfiguration.StartMessageId; if (readerConfiguration.ReaderName != null) { consumerConfiguration.ConsumerName = readerConfiguration.ReaderName; } if (readerConfiguration.ResetIncludeHead) { consumerConfiguration.ResetIncludeHead = true; } consumerConfiguration.CryptoFailureAction = readerConfiguration.CryptoFailureAction; if (readerConfiguration.CryptoKeyReader != null) { consumerConfiguration.CryptoKeyReader = readerConfiguration.CryptoKeyReader; } if (readerConfiguration.KeyHashRanges != null) { consumerConfiguration.KeySharedPolicy = KeySharedPolicy.StickyHashRange().GetRanges(readerConfiguration.KeyHashRanges.ToArray()); } var partitionIdx = TopicName.GetPartitionIndex(readerConfiguration.TopicName); var consumerId = generator.Ask <long>(NewConsumerId.Instance).GetAwaiter().GetResult(); _child = Context.ActorOf(Props.Create(() => new ConsumerActor <T>(consumerId, stateA, clientActor, lookup, cnxPool, generator, readerConfiguration.TopicName, consumerConfiguration, Context.System.Scheduler.Advanced, partitionIdx, true, readerConfiguration.StartMessageId, readerConfiguration.StartMessageFromRollbackDurationInSec, schema, true, client))); _child.Tell(Connect.Instance); if (isLive) { LiveConsume(); } else { Consume(); } }
public void SubscribeTo(ConsumerName consumerName, Topic topic, EventReceived received) { _logger.Information($"Listening on topic '{topic}' from '{_configuration.ConnectionString}'"); var consumer = new Confluent.Kafka.Consumer <Ignore, string>(_configuration.GetFor(consumerName), null, new StringDeserializer(Encoding.UTF8)); consumer.Assign(new [] { new TopicPartition(topic, 0) }); consumer.OnMessage += (_, message) => { try { received(topic, message.Value); consumer.CommitAsync(); } catch (Exception ex) { _logger.Error(ex, "Couldn't handle received message"); } }; consumer.OnError += (_, message) => _logger.Error(message.Reason); Task.Run(() => { for (;;) { consumer.Poll(TimeSpan.FromMilliseconds(50)); } }); }
private void PersistPactFile() { var responsePact = _mockProviderService.SendAdminHttpRequest(HttpVerb.Post, Constants.PactPath); if (_mockProviderService.UseRemoteMockService) { File.WriteAllText($"{_pactDir}\\{ConsumerName.ToLower()}{ProviderName.ToLower()}.json", responsePact); } }
public override string ToString() { if (ConsumerLastName.Trim() != "" || ConsumerName.Trim() != "") { return($"{CompanyName} - {ConsumerName} {ConsumerLastName}"); } return($"{CompanyName}"); }
private void PersistPactFile() { var responsePact = _mockProviderService.SendAdminHttpRequest(HttpVerb.Post, Constants.PactPath); if (_mockProviderService.UseRemoteMockService) { string fileName = ConsumerName.ToLower() + ProviderName.ToLower() + ".json"; File.WriteAllText(Path.Combine(_pactDir, fileName), responsePact); } }
//[Ignore("PACT FLOW")] public void PublishToPactFlow() { // fake Git HashCode (only for demo) var version = "725c611"; // master (only for demo) var tags = new[] { "master" }; var token = Environment.GetEnvironmentVariable("PACT_BROKER_TOKEN"); var pactPublisher = new PactPublisher("https://expandtesting.pact.dius.com.au", new PactUriOptions(token)); pactPublisher.PublishToBroker($"../../../../../pacts/{ConsumerName.ToLower()}-{ProviderName.ToLower()}.json", version, tags); }
public HeartbeatReply MapToRequest(Message message) { var messageBody = JsonSerializer.Deserialize <HeartBeatResponseBody>(message.Body.Value, JsonSerialisationOptions.Options); var replyAddress = new ReplyAddress(message.Header.Topic, message.Header.CorrelationId); var reply = new HeartbeatReply(messageBody.HostName, replyAddress); foreach (var consumer in messageBody.Consumers) { var consumerName = new ConsumerName(consumer.ConsumerName); reply.Consumers.Add(new RunningConsumer(consumerName, consumer.State)); } return(reply); }
public IPactVerifier HonoursPactWith(string consumerName) { if (String.IsNullOrEmpty(consumerName)) { throw new ArgumentException("Please supply a non null or empty consumerName"); } if (!String.IsNullOrEmpty(ConsumerName) && !ConsumerName.Equals(consumerName)) { throw new ArgumentException("Please supply the same consumerName that was defined when calling the ProviderStatesFor method"); } ConsumerName = consumerName; return(this); }
public IProviderStates ProviderStatesFor(string consumerName, Action setUp = null, Action tearDown = null) { if (String.IsNullOrEmpty(consumerName)) { throw new ArgumentException("Please supply a non null or empty consumerName"); } if (!String.IsNullOrEmpty(ConsumerName) && !ConsumerName.Equals(consumerName)) { throw new ArgumentException("Please supply the same consumerName that was defined when calling the HonoursPactWith method"); } ConsumerName = consumerName; ProviderStates = new ProviderStates(setUp, tearDown); return(this); }
public List <Message> Validate() { var errors = new List <Message>(); if (CompanyName.Trim() == "" && (ConsumerName.Trim() == "" && ConsumerLastName.Trim() == "")) { errors.Add(new Message("Należy podać nazwe firmy lub imię i nazwisko")); } var rgx = new Regex("^[0-9]{10}"); var nip = Nip.Replace("-", "").Replace(" ", "").Trim(); if (!rgx.IsMatch(nip) && Nip.Trim() != "") { errors.Add(new Message("Nip jest niepoprawny")); } return(errors); }
public HeartbeatReply MapToRequest(Message message) { var messageBody = JObject.Parse(message.Body.Value); var hostName = (string)messageBody["HostName"]; var replyAddress = new ReplyAddress(message.Header.Topic, message.Header.CorrelationId); var reply = new HeartbeatReply(hostName, replyAddress); var consumers = (JArray)messageBody["Consumers"]; foreach (var consumer in consumers) { var consumerName = new ConsumerName((string)consumer["ConsumerName"]); var state = (ConsumerState)Enum.Parse(typeof(ConsumerState), (string)consumer["State"]); reply.Consumers.Add(new RunningConsumer(consumerName, state)); } return(reply); }
/// <summary> /// Returns true if OrderItem instances are equal /// </summary> /// <param name="input">Instance of OrderItem to be compared</param> /// <returns>Boolean</returns> public bool Equals(OrderItem input) { if (input == null) { return(false); } return (( Name == input.Name || Name != null && Name.Equals(input.Name) ) && ( MerchantSuppliedId == input.MerchantSuppliedId || MerchantSuppliedId != null && MerchantSuppliedId.Equals(input.MerchantSuppliedId) ) && ( Price == input.Price || Price != null && Price.Equals(input.Price) ) && ( Quantity == input.Quantity || Quantity != null && Quantity.Equals(input.Quantity) ) && ( Extras == input.Extras || Extras != null && Extras.SequenceEqual(input.Extras) ) && ( ConsumerName == input.ConsumerName || ConsumerName != null && ConsumerName.Equals(input.ConsumerName) ) && ( SpecialInstructions == input.SpecialInstructions || SpecialInstructions != null && SpecialInstructions.Equals(input.SpecialInstructions) )); }
public DataRecord Pop(ConsumerName con) { DataRecord recout; switch (con) { case ConsumerName.GUI: lock (bufgui) { if (bufgui.Count > 0) { recout = bufgui.Dequeue(); } else { recout = null; } } break; case ConsumerName.APP: lock (bufapp) { if (bufapp.Count > 0) { recout = bufapp.Dequeue(); } else { recout = null; } } break; default: recout = null; throw new NotImplementedException(); } return(recout); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; if (Name != null) { hashCode = hashCode * 59 + Name.GetHashCode(); } if (MerchantSuppliedId != null) { hashCode = hashCode * 59 + MerchantSuppliedId.GetHashCode(); } if (Price != null) { hashCode = hashCode * 59 + Price.GetHashCode(); } if (Quantity != null) { hashCode = hashCode * 59 + Quantity.GetHashCode(); } if (Extras != null) { hashCode = hashCode * 59 + Extras.GetHashCode(); } if (ConsumerName != null) { hashCode = hashCode * 59 + ConsumerName.GetHashCode(); } if (SpecialInstructions != null) { hashCode = hashCode * 59 + SpecialInstructions.GetHashCode(); } return(hashCode); } }
public ReaderActor(long consumerId, IActorRef stateActor, IActorRef client, IActorRef lookup, IActorRef cnxPool, IActorRef idGenerator, ReaderConfigurationData <T> readerConfiguration, IAdvancedScheduler listenerExecutor, ISchema <T> schema, ClientConfigurationData clientConfigurationData) { _generator = idGenerator; var subscription = "reader-" + ConsumerName.Sha1Hex(Guid.NewGuid().ToString()).Substring(0, 10); if (!string.IsNullOrWhiteSpace(readerConfiguration.SubscriptionRolePrefix)) { subscription = readerConfiguration.SubscriptionRolePrefix + "-" + subscription; } ConsumerConfigurationData <T> consumerConfiguration = new ConsumerConfigurationData <T>(); consumerConfiguration.TopicNames.Add(readerConfiguration.TopicName); consumerConfiguration.SubscriptionName = subscription; consumerConfiguration.SubscriptionType = SubType.Exclusive; consumerConfiguration.SubscriptionMode = SubscriptionMode.NonDurable; consumerConfiguration.ReceiverQueueSize = readerConfiguration.ReceiverQueueSize; consumerConfiguration.ReadCompacted = readerConfiguration.ReadCompacted; // Reader doesn't need any batch receiving behaviours // disable the batch receive timer for the ConsumerImpl instance wrapped by the ReaderImpl consumerConfiguration.BatchReceivePolicy = _disabledBatchReceivePolicy; if (readerConfiguration.StartMessageId != null) { consumerConfiguration.StartMessageId = (BatchMessageId)readerConfiguration.StartMessageId; } if (readerConfiguration.ReaderName != null) { consumerConfiguration.ConsumerName = readerConfiguration.ReaderName; } if (readerConfiguration.ResetIncludeHead) { consumerConfiguration.ResetIncludeHead = true; } if (readerConfiguration.ReaderListener != null) { var readerListener = readerConfiguration.ReaderListener; consumerConfiguration.MessageListener = new MessageListenerAnonymousInnerClass(Self, readerListener); } consumerConfiguration.CryptoFailureAction = readerConfiguration.CryptoFailureAction; if (readerConfiguration.CryptoKeyReader != null) { consumerConfiguration.CryptoKeyReader = readerConfiguration.CryptoKeyReader; } if (readerConfiguration.KeyHashRanges != null) { consumerConfiguration.KeySharedPolicy = KeySharedPolicy.StickyHashRange().GetRanges(readerConfiguration.KeyHashRanges.ToArray()); } int partitionIdx = TopicName.GetPartitionIndex(readerConfiguration.TopicName); if (consumerConfiguration.ReceiverQueueSize == 0) { _consumer = Context.ActorOf(Props.Create(() => new ZeroQueueConsumer <T>(consumerId, stateActor, client, lookup, cnxPool, _generator, readerConfiguration.TopicName, consumerConfiguration, listenerExecutor, partitionIdx, false, readerConfiguration.StartMessageId, schema, true, clientConfigurationData))); } else { _consumer = Context.ActorOf(Props.Create(() => new ConsumerActor <T>(consumerId, stateActor, client, lookup, cnxPool, _generator, readerConfiguration.TopicName, consumerConfiguration, listenerExecutor, partitionIdx, false, readerConfiguration.StartMessageId, readerConfiguration.StartMessageFromRollbackDurationInSec, schema, true, clientConfigurationData))); } Receive <HasReachedEndOfTopic>(m => { _consumer.Tell(m, Sender); }); Receive <AcknowledgeCumulativeMessage <T> > (m => { _consumer.Tell(m, Sender); }); Receive <Messages.Consumer.Receive> (m => { _consumer.Tell(m, Sender); }); Receive <Connect> (m => { _consumer.Tell(m, Sender); }); Receive <MessageProcessed <T> > (m => { _consumer.Tell(m, Sender); }); Receive <HasMessageAvailable> (m => { _consumer.Tell(m, Sender); }); Receive <GetTopic> (m => { _consumer.Tell(m, Sender); }); Receive <IsConnected> (m => { _consumer.Tell(m, Sender); }); Receive <SeekMessageId> (m => { _consumer.Tell(m, Sender); }); Receive <SeekTimestamp> (m => { _consumer.Tell(m, Sender); }); }
public async Task PublishToPactBroker() { var pactPublisher = new PactPublisher("http://localhost:8090"); pactPublisher.PublishToBroker($"../../pacts/{ConsumerName.ToLower()}-{ProviderName.ToLower()}.json", "1.0.0"); }
public MultiTopicsReader(IActorRef state, IActorRef client, IActorRef lookup, IActorRef cnxPool, IActorRef idGenerator, ReaderConfigurationData <T> readerConfiguration, IAdvancedScheduler listenerExecutor, ISchema <T> schema, ClientConfigurationData clientConfigurationData) { _generator = idGenerator; var subscription = "multiTopicsReader-" + ConsumerName.Sha1Hex(Guid.NewGuid().ToString()).Substring(0, 10); if (!string.IsNullOrWhiteSpace(readerConfiguration.SubscriptionRolePrefix)) { subscription = readerConfiguration.SubscriptionRolePrefix + "-" + subscription; } var consumerConfiguration = new ConsumerConfigurationData <T>(); foreach (var topic in readerConfiguration.TopicNames) { consumerConfiguration.TopicNames.Add(topic); } consumerConfiguration.SubscriptionName = subscription; consumerConfiguration.SubscriptionType = SubType.Exclusive; consumerConfiguration.SubscriptionMode = SubscriptionMode.NonDurable; consumerConfiguration.ReceiverQueueSize = readerConfiguration.ReceiverQueueSize; consumerConfiguration.ReadCompacted = readerConfiguration.ReadCompacted; if (readerConfiguration.ReaderListener != null) { var readerListener = readerConfiguration.ReaderListener; consumerConfiguration.MessageListener = new MessageListenerAnonymousInnerClass(Self, readerListener); } if (readerConfiguration.StartMessageId != null) { consumerConfiguration.StartMessageId = (BatchMessageId)readerConfiguration.StartMessageId; } if (readerConfiguration.ReaderName != null) { consumerConfiguration.ConsumerName = readerConfiguration.ReaderName; } if (readerConfiguration.ResetIncludeHead) { consumerConfiguration.ResetIncludeHead = true; } consumerConfiguration.CryptoFailureAction = readerConfiguration.CryptoFailureAction; if (readerConfiguration.CryptoKeyReader != null) { consumerConfiguration.CryptoKeyReader = readerConfiguration.CryptoKeyReader; } if (readerConfiguration.KeyHashRanges != null) { consumerConfiguration.KeySharedPolicy = KeySharedPolicy.StickyHashRange().GetRanges(readerConfiguration.KeyHashRanges.ToArray()); } _consumer = Context.ActorOf(Props.Create(() => new MultiTopicsConsumer <T>(state, client, lookup, cnxPool, _generator, consumerConfiguration, listenerExecutor, schema, true, readerConfiguration.StartMessageId, readerConfiguration.StartMessageFromRollbackDurationInSec, clientConfigurationData))); ReceiveAsync <SubscribeAndCreateTopicsIfDoesNotExist>(async subs => { _sender = Sender; await SubscribeAndCreateTopics(subs); }); ReceiveAsync <Subscribe>(async sub => { _sender = Sender; await SubscribeToTopic(sub); }); Receive <HasReachedEndOfTopic>(m => { _consumer.Tell(m, Sender); }); Receive <AcknowledgeCumulativeMessage <T> >(m => { _consumer.Tell(m, Sender); }); Receive <MessageProcessed <T> >(m => { _consumer.Tell(m, Sender); }); Receive <Messages.Consumer.Receive>(m => { _consumer.Tell(m, Sender); }); Receive <HasMessageAvailable>(m => { _consumer.Tell(m, Sender); }); Receive <GetTopic>(m => { _consumer.Tell(m, Sender); }); Receive <IsConnected>(m => { _consumer.Tell(m, Sender); }); Receive <SeekMessageId>(m => { _consumer.Tell(m, Sender); }); Receive <SeekTimestamp>(m => { _consumer.Tell(m, Sender); }); ReceiveAny(m => { _consumer.Tell(m, Sender); }); }
public RunningConsumer(ConsumerName consumerName, ConsumerState state) { ConsumerName = consumerName; State = state; }