Example #1
0
 /// <summary>Undeploy the service</summary>
 /// <returns>Response of the service undeployment</returns>
 public async Task UndeployService()
 {
     await CallService(new CallServiceParameters {
         ReceiverId = Constants.ServiceManagerId,
         Action     = Constants.ActionUnDeploy,
         Headers    = new List <Header> {
             BusConnection.CreateHeader(Constants.Platform6AppKey + "node.id", _nodeId),
             BusConnection.CreateHeader(Constants.Platform6AppKey + "service.id", _id)
         }
     });
 }
Example #2
0
        /// <summary>Deploy the service</summary>
        /// <param name="parameters">Deployment parameters</param>
        /// <returns>Response of the service deployment</returns>
        private async Task DeployService(DeployParameters parameters)
        {
            if (Client == null)
            {
                await CreateHazelcastClient();
            }

            await CallService(new CallServiceParameters {
                ReceiverId = Constants.ServiceManagerId,
                Action     = Constants.ActionDeploy,
                Headers    = new List <Header> {
                    BusConnection.CreateHeader(Constants.Platform6AppKey + "node.id", _nodeId),
                    BusConnection.CreateHeader(Constants.Platform6AppKey + "service.id", _id),
                    BusConnection.CreateHeader(Constants.Platform6AppKey + "service.path", parameters.Path),
                    BusConnection.CreateHeader(Constants.Platform6AppKey + "service.ctx", parameters.BasePath),
                    BusConnection.CreateHeader(Constants.Platform6AppKey + "service.version", parameters.Versions.Server),
                    BusConnection.CreateHeader(Constants.Platform6AppKey + "service.ui.version", parameters.Versions.Client),
                    BusConnection.CreateHeader(Constants.Platform6AppKey + "service.ui", JsonConvert.SerializeObject(parameters.Ui))
                }
            });
        }
Example #3
0
        /// <summary>Send a request to another service</summary>
        /// <param name="parameters">Required parameters for the request</param>
        /// <returns>Response of the service</returns>
        public async Task <CommonMessage> CallService(CallServiceParameters parameters)
        {
            var receiverId  = parameters.ReceiverId;
            var headers     = new List <Header>();
            var attachments = parameters.Attachments ?? new List <Attachment>();

            if (parameters.Username != null)
            {
                headers.Add(BusConnection.CreateHeader(Constants.RequestPrefix + "user", parameters.Username));
            }
            if (parameters.Action != null)
            {
                headers.Add(BusConnection.CreateHeader(Constants.RequestPrefix + "action", parameters.Action));
            }
            if (parameters.Headers != null)
            {
                headers.AddRange(parameters.Headers);
            }

            var commonMessage = Task.Run(() => BusConnection.CreateCommonMessage(_idKey, parameters.ReceiverId, headers, attachments)).Result;

            return(await SendCommonMessage(receiverId, commonMessage));
        }
Example #4
0
        /// <summary>Send a message to another service</summary>
        /// <param name="receiverId">Identifier of the service receiving the message</param>
        /// <param name="commonMessage">Message sent</param>
        /// <returns>Response of the common message sent</returns>
        public async Task <CommonMessage> SendCommonMessage(string receiverId, CommonMessage commonMessage)
        {
            var receiverIdKey = Constants.ReceiverIdPrefix + receiverId;
            var request       = Client.GetQueue <CommonMessage>(receiverIdKey);
            var isSent        = Task.Run(() => request.Offer(commonMessage)).Result;

            if (!isSent)
            {
                throw new Exception("Unable to send the common message with id " + commonMessage.Id + "!");
            }

            BusConnection.DisplayCommonMessage(commonMessage);

            var response = Task.Run(() => Client.GetQueue <CommonMessage>(_idKey).Take()).Result;

            BusConnection.DisplayCommonMessage(response);

            if (!response.Id.Equals(commonMessage.Id))
            {
                throw new Exception("Common message response's id " + response.Id + " is not the same as the common message request's id " + commonMessage.Id + "!");
            }

            return(response);
        }