Mutithreading and concurrent processing - multithreading

I have a small question on mutlithreading.
-I want to start to a thread after some successful pre validations.
-If the pre validation fails, there will not be any thread created and the
control is sent back to the user with some error message.
- **If the validation is successful, then i need to send user a success response like a pop with msg "request accepted" and in parallel the thread should be executed.
- Once the thread is executed, each thread returns some response and
the response is sent as an email.
- **The tricky part here is, how can i return a success response back to the user and execute the thread in parallel.
-**FYI, i am using executor framework for submitting the task and retrieving the response in future object and email the data in future object.
Thanks In Advance

Related

Send email notification failure Azure data factory Pipeline not working (Web Job)

I have a pipeline where the following activities takes place
Lookup-> Lookup ->ForEach->(Stored Procedure)-> Send Success Email/ Send Failure Email
Once the pipeline successfully completed its execution, I see a successful email in my inbox, however for any reason the foreach activity fails I don't see a Failure Email.
Inside Foreach Stored procedure might get executed dynamically sometimes based on N number of times.
Inside foreach I have only one activity (Stored Procedure execution).
This is the configuration for Email Failure message, I do try to pull the dynamic error message, so I have added a code as "ErrorMessage":"#{activity('Lookup').output.message}", It shows me
Error.Message is not a property, Moreover I wanted to get a Failure email
Configuration for Success Email, works perfectly fine
I have achieved the above task by modifying my pipeline with
Lookup->Lookup->ForEach(Stored Procedure -> If Condition-> WaitTrue/WaitFalse -> WebJob to send email which I have added to a separate pipeline)
Under if condition activity checking for Error status from previous activity
#contains(activity('Load Tables').Status,'Succeeded')
In case of Failure, the status would be Error and catching the message as
"errorMessage":"#{activity('Load Tables').Error.message}"

Taking an action when HTTP response status is not 200

I'm new to Spring Integration. I have a simple flow which send request to external resource with several attemps.
IntegrationFlows.from(MY_CHANNEL)
.handle(myOutboundGateway, e -> e.advice(myRetryAdvice))
.wireTap(logResponse())
.get();
What I need to do is to take some action (saving data to a database) when calling external resource (after retrying) is not succesful (http status code is not 200 OK). How can I achieve that in my flow?
When all the attempts of the retry are exhausted, the RecoveryCallback is called.
See some sample here: How to get HTTP status in advice recovery callback. In that RecoveryCallback you can just return null and send a message to some channel for that storing to DB logic.
Another way is to have extra advice on top of that retry instead of RecoveryCallback. See its docs: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#expression-advice. This way when all the attempts are done, the exception is going to be bubbled and caught by that ExpressionEvaluatingRequestHandlerAdvice and its failureChannel. Pay attention to the trapException = true, so the error doesn't go back to the flow. Only to that failureChannel for your DB logic.

Send API response in AWS after that, run process in background (async)

I do have an endpoint DELETE book/{bookname}. When user request to endpoint, he/she have to get response "This book will be deleted after 10 minute". And after sending response, another function will start and delete book from database after 10 minutes. I have to use async only and Python 3.7. I have succeeded, all of them works fine ,except sending response to user.
Now, User sends request to DELETE /book/{bookname} and waits... (background processes will delete after 10 minutes) . after some seconds due to timeout, user receives "Request Timeout". I just want to send success message to user (it does not matter book will be deleted or not) and run processes background in AWS Lambda. (I must not use invoke and stepfunctions)

How to ensure message will be there for 10 minutes in queue

I have two applications App1 Console app and App2 Azure func App
App1 is for enroll new customer
App2 is for activate account for new customer
We need to ensure that each message that App1 sends is stored in a queue for 10 minutes before App2 uses the message
From App1 I'm taking inputs like customer-id , customer-name and send this message to queue.
using simple code -
// Create a new message to send to the queue
string messageBody = $"Message {i}";
var message = new Message(Encoding.UTF8.GetBytes(messageBody));
// Write the body of the message to the console
Console.WriteLine($"Sending message: {messageBody}");
// Send the message to the queue
await queueClient.SendAsync(message);
do i need to add any setting for 10 minutes scenario?
From App2 I need to read this message but need to ensure for 10 minutes before App2 uses the message.
How to achieve this to ensure message there for 10 minutes in queue.
When i search on stackoverflow i found this
If a message is added with a 5 minute timeout it will only be processed after that.
it means while sending message i need to set something ?
It looks like you're looking for Scheduled messages.
You can submit messages to a queue or topic for delayed processing; for example, to schedule a job to become available for processing by a system at a certain time. This capability realizes a reliable distributed time-based scheduler.
Scheduled messages do not materialize in the queue until the defined enqueue time. Before that time, scheduled messages can be canceled. Cancellation deletes the message.
You can schedule messages either by setting the ScheduledEnqueueTimeUtc property when sending a message through the regular send path, or explicitly with the ScheduleMessageAsync API. The latter immediately returns the scheduled message's SequenceNumber, which you can later use to cancel the scheduled message if needed. Scheduled messages and their sequence numbers can also be discovered using message browsing.

The remote server returned an error: (404) Not Found While deleting message from queue

We are using Azure Queue for our printing job but when deleting message from queue by queue.DeleteMessage(message), the method throws below exception.
The remote server returned an error: (404) Not Found
Above exception was handled but still looking for workaround.
Can anyone please suggest how to fix it.
Thanks,
Sneh
According to this article, we can find that:
After a client retrieves a message with the Get Messages operation,
the client is expected to process and delete the message. To delete
the message, you must have two items of data returned in the response
body of the Get Messages operation:
The message ID, an opaque GUID value that identifies the message in the queue.
A valid pop receipt, an opaque value that indicates that the message has been retrieved.
If a message with a matching pop receipt is not found, the service returns error code 404 (Not Found). And Pop receipts remain valid until one of the following events occurs:
The message has expired.
The message has been deleted using the last pop receipt received
either from Get Messages or Update Message.
The invisibility timeout has elapsed and the message has been
dequeued by a Get Messages request. When the invisibility timeout
elapses, the message becomes visible again. If it is retrieved by
another Get Messages request, the returned pop receipt can be used
to delete or update the message.
The message has been updated with a new visibility timeout. When the
message is updated, a new pop receipt will be returned.
I ran into this issue today and the root cause was ownership issues between two different queues. We had setup two queues, one to hold our message awaiting processing and one for messages that had errored out. The problem came with the logic of how the message was moved between queues.
If our processing failed, we would perform the following logic:
_errorQueue.AddMessage(msg);
_queue.DeleteMessage(msg);
The DeleteMessage would also return a (404) Not Found because the msg had been moved to the errorQueue. There were two solutions that I found to this issue:
1. Switch Logic
If you switch the logic than the msg will be deleted before being added to the errorQueue which will avoid the ownership swap.
_queue.DeleteMessage(msg);
_errorQueue.AddMessage(msg);
2. Insert Copy of Message
Solution #1 has the potential to lose the message if something happens between deletion and insertion (small chance but a chance nonetheless). The solution I went with inserted a copy of the msg with the same payload so it didn't run into this ownership issue because it was a different object.
_errorQueue.AddMessage(new CloudQueueMessage(msg.AsString));
_queue.DeleteMessage(msg);
Debugging Tip
One useful tip I encountered while debugging it making sure the exception your catching isn't the default Exception. Catch the StorageException instead to get access to Azure Storage related error information.
try
{
_queue.DeleteMessage(msg);
}
catch (StorageException ex) //use this instead of base Exception
{
var info = ex.RequestInformation; //has useful information
}
If can provide more information to help you debug your real issue.

Resources