Controller code:
[HttpPost]
[Route("mood")]
public async Task<IActionResult> ProcessMoodProfile([FromBody] MoodTelemetryDTO moodProfile)
{
string userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
var result = await _moodDataService.ProcessMoodTelemetryData(userId, moodProfile).ConfigureAwait(false);
return Ok(HttpStatusCode.Created);
}
Data service code:
public async Task<bool> ProcessMoodTelemetryData(string userId, MoodTelemetryDTO moodTelemetry)
{
try
{
var moodProfile = mapper.Map<MoodTelemetryProfile>(moodTelemetry);
moodProfile.CreatedAt = moodTelemetry.CreatedDate.Date;
moodProfile.UserId = new Guid(userId);
return await _sendTelemetryData.SendMessageAsync(TelemetryType.MoodTelemetry, userId, JsonConvert.SerializeObject(moodProfile), new System.Threading.CancellationToken()).ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.LogError(ex, "Unable to process telemetry data. MethodName {methodname}", nameof(ProcessMoodTelemetryData));
return false;
}
}
EventHubTelemetrySinkService
public async Task<bool> SendMessageAsync(TelemetryType telemetryType, string partitionKey, string messagejson, CancellationToken cancellationToken)
{
var status = false;
_client = _sink[telemetryType];
if (_client == null)
{
_logger.LogError("User telemetry data processes successfully but no sink found for the telemetry type {telemetryType}", telemetryType);
}
using (_logger.BeginScope("Send Message"))
{
_logger.LogInformation($"Message to be send {messagejson}");
_logger.LogInformation($"Type of Telemetry {telemetryType}");
var data = new Microsoft.Azure.EventHubs.EventData(Encoding.UTF8.GetBytes(messagejson));
try
{
await SendMessageInternalAsync(data, partitionKey, cancellationToken).ConfigureAwait(false);
status = true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Error Sending Message. Method {methodName}", nameof(SendMessageAsync));
}
data.Dispose();
}
return status;
}
private async Task SendMessageInternalAsync(Microsoft.Azure.EventHubs.EventData messgae, string partitionKey, CancellationToken cancellationToken)
{
var success = false;
var attempt = 0;
using (_logger.BeginScope("Send Message Internal"))
{
do
{
try
{
await _client.SendAsync(messgae, partitionKey).ConfigureAwait(false);
var response = _client.SendAsync(messgae, partitionKey).ConfigureAwait(false);
success = true;
}
catch (Exception ex)
{
if (attempt == _messageRetryCount || cancellationToken.IsCancellationRequested)
{
_logger.LogError(ex, "Internal message retry exceeded or cancellation invoked. method {methodname}", nameof(SendMessageInternalAsync));
}
}
} while (!success && ++attempt <= _messageRetryCount && !cancellationToken.IsCancellationRequested);
}
}
This code is working earlier, but from few days it stopped working. sendasync function receive all the values and no exception is there, still values are not stored in database.