protected virtual Func <ProducerRequest, ProducerResponse> ProducerConnectAndSendAction() { Func <ProducerRequest, ProducerResponse> producerAction = (request) => { Session.ClientBehavior.ProducerConnect(request.SenderId); var producer = Session.CreateOrGetProducer(request.SenderId); Session.SubscribeProducer(request.Topic, producer); this.Session .QueueService .CreateTopicQueuesIfNotExists(request.Topic, QueueCountWithEeachTopic); producer.StartWorkingDate = DateTime.Now; var queueMessage = QueueMessage.Create(request.Header, request.Body, request.Topic); bool sendResult = Session.MessageManager.TrySendMessage( request.Topic, producer.ClientId, queueMessage ); var storeResult = this.Session.MessageManager.MessageStore.Store(queueMessage); // how about strore failure? log or send message to producer? var response = Session.MessageManager.ProducerMessageBuilder.BuildResponseMessage( topic: request.Topic, body: request.Body, senderId: request.SenderId ); response.SendSuccess = sendResult; return(response); }; return(producerAction); }