/// <summary> /// This method publishes an event to the configured queue. /// </summary> /// <param name="message">Represents the message body.</param> /// <returns>The result of the publishing.</returns> public Task <string> PublishEvent(dataToA2e message) { if (message == null) { throw new ArgumentNullException(nameof(message), "Cannot be null."); } return(Task.Factory.StartNew(() => { try { var factory = new ConnectionFactory { Uri = new Uri(_queueUrl), Ssl = { Version = SslProtocols.Tls12 } }; using (IConnection conn = factory.CreateConnection()) { using (IModel channel = conn.CreateModel()) { channel.BasicReturn += MqBasicReturn; string serializedMessage = JsonConvert.SerializeObject(message); var messageBody = Encoding.UTF8.GetBytes(serializedMessage); IBasicProperties basicproperties = channel.CreateBasicProperties(); basicproperties.Persistent = true; channel.BasicPublish(_exchangeName, _routingKey, basicProperties: basicproperties, mandatory: true, body: messageBody); Console.WriteLine("[ {0} ] : SUBMIT DAMAGES : Data sent to A2E : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), serializedMessage); channel.BasicReturn -= MqBasicReturn; } } return $"[ {ApiHelpers.GetCurrentTimeStamp(DateTime.Now)} ] The message has " + "been successfully published."; } catch (Exception e) { WebHook.RunAsync(e.Message).GetAwaiter().GetResult(); return $"Error while subitting the event to the excahnge {_exchangeName} " + $"with routing key {_routingKey}. Error message [ {e.Message} ]."; } })); }
public async Task <object> PostSubmitDamages(string id, [FromBody] SubmitDamageInputs dataFromDg) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Cannot be null or empty"); } if (dataFromDg == null) { throw new ArgumentNullException(nameof(dataFromDg), "Cannot be null."); } Console.WriteLine( "[ {0} ] : SUBMIT DAMAGES : call made with claim ID : [ {1} ] and damages data : [ {2} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id, Convert.ToString(dataFromDg)); Console.WriteLine( "[ {0} ] : SUBMIT DAMAGES : Get claim call made to validate Claim in MBE with Claim ID : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id); string existingClaim = await _mbe.GetClaim(id); if (string.IsNullOrEmpty(existingClaim)) { return(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(string.Format("No claim found with ID {0}", id)), ReasonPhrase = "No content found with given claim Id" }); } ClaimInputs claimDataObj = JsonConvert.DeserializeObject <ClaimInputs>(existingClaim); if (!string.IsNullOrEmpty(dataFromDg.damageComment)) { HttpResponseMessage submitCommentsResponse = await _mbe.SubmitClaimComments(id, claimDataObj.claimNumber, claimDataObj.orgId, dataFromDg.damageComment); Console.WriteLine( $"[ {ApiHelpers.GetCurrentTimeStamp(DateTime.Now)} ] : SUBMIT ATTACHMENT COMMENTS RESULT: " + $"{submitCommentsResponse.Content.ReadAsStringAsync().Result}"); } var a2EHeader = new a2eHeaders { id = ApiHelpers.GetRandomString(), cid = ApiHelpers.GetRandomString(), messageType = "createestimaterequest" }; var a2EBody = new a2eBody { capturedDamage = dataFromDg.capturedDamage, vinDecodeFailed = claimDataObj.vinDecodeFailed, mileage = dataFromDg.mileage }; var dataToA2E = new dataToA2e { header = a2EHeader, claimContext = new ClaimContext { workAssignmentId = claimDataObj.workAssignmentPK, createdForProfileId = !string.IsNullOrEmpty(claimDataObj.externalId) ? claimDataObj.externalId : "477T2PPCOMPAPP2", orgId = claimDataObj.orgId }, body = a2EBody }; string publishingResults = await _eventManager.PublishEvent(dataToA2E); Console.WriteLine(publishingResults); return("Received damage data successfully"); }