public CamoranConsumer CreateConsumer(Guid id) { ClientConfig config = new ClientConfig { Address = _address, Port = _port }; var inner = new Client_byHelios <ConsumerRequest, ConsumerResponse>(id, config); var producer = new CamoranConsumer(id, config, inner); return(producer); }
public void Single_Sender_Send_Message_with_Single_Consmer() { byte[] sendBody = Encoding.UTF8.GetBytes(sendString); CamoranProducer producer = null; CamoranConsumer consumer = null; producer = produerTestcase .CreateProducer() .BindTopic(topic) .SetBody(sendBody) .BindSendCallBack((response) => { sendCount++; Debug.WriteLine("sendCount:" + sendCount); isSendOver = sendCount == TestConfig.Producer_Send_Count; if (isSendOver) { producer.Stop(); producer.Close(); } }); ; consumer = consumerTestcase.CreateConsumer(Guid.NewGuid()) .SubscribeTopic(topic) .RegisteConsumeAction((response) => { consumeCount++; Debug.WriteLine("ConsumeCount:" + consumeCount); isConsumeOver = consumeCount >= TestConfig.Producer_Send_Count; if (isConsumeOver) { consumer.Stop(); consumer.Close(); } receiveString = Encoding.UTF8.GetString(response.QueueMeesageBody); }); ; producer.Start(); consumer.Start(); //producer.Close(); //producer.Stop(); Assert.IsTrue(isConsumeOver); Assert.AreEqual(sendString, receiveString); }
public void Start_Consume_Whole_Action_with_Mulit_Thread_Diff_Consumer_Test() { int consumeCount = 0; for (int i = 0; i < TestConfig.consumerCount; i++) { new TaskFactory().StartNew(() => { var body = System.Text.Encoding.UTF8.GetBytes("Hello World" + i); CamoranConsumer consumer = null; consumer = CreateConsumer(Guid.NewGuid()) .SubscribeTopic("topic1") .SetMessageBody(body) .RegisteConsumeAction((response) => { lock (obj) { consumeCount++; var responseBody = System.Text.Encoding.UTF8.GetString(response.Body); var queueMessageBody = System.Text.Encoding.UTF8.GetString(response.QueueMeesageBody); Console.WriteLine(responseBody + " " + consumeCount + " QueueMessageId:" + response.QueueMessageId + " QueueMessageBody:" + queueMessageBody + "From Queue Id:" + response.FromQueueId + "Consumed by :" + response.SenderId ); } }); consumer.ConnectToServer(); consumer.Start(); }); } Console.ReadLine(); Assert.AreEqual(consumeCount, TestConfig.Producer_Send_Count); }
public void SubscribeConsumer(string topic, CamoranConsumer consumer) { consumer.SubscribeTopic(topic); this.ConsumerManager.AddClient(topic, consumer); }