spring-async | Asynchronous REST call with DeferredResult | Object-Relational Mapping library
kandi X-RAY | spring-async Summary
kandi X-RAY | spring-async Summary
Asynchronous REST call with DeferredResult
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Aggregate response
- Executes the given task
- Sends an error response
- Handles a successful response
- Checks if the task finished
- Returns an unmodifiable list of urls
- Starts the timer
- Time callable
- Creates a time response
- Create a deferred request
- Time Basic Request
- Time response entity request entity
- Get the message body
- Main entry point for the Async application
spring-async Key Features
spring-async Examples and Code Snippets
Community Discussions
Trending Discussions on spring-async
QUESTION
I have a Spring Integration flow
which uploads the files to sftp server asynchronously, files to be uploaded are coming from http endpoint. Initially I faced same problem as discussed here glad it got solved.
In the same SO thread I found this comment.
In enterprise environments, you often have files of sizes you cannot afford to buffer into memory like that. Sadly enough, InputStreamResource won't work either. Your best bet, as far as I could tell so far, is to copy contents to an own temp file (e.g. File#createTempFile) which you can clean up at the end of the processing thread.
Currently I'm connecting file inputstream to InputStreamResource
to get rid of the problem, its working flawlessly. why does the commenter say InputStreamResource won't work either, AFAIK InputStream
never store data in memory
Does the InputStreamResource
's inputStream gets closed automatically after file upload?
When we say large file how much of file size are we talking about here. currently in my case 2-5 Mb of files are uploaded to SFTP
Do I really need to care about changing my file upload mechanism to one something like storing in temp folder?
Code Sample:
...ANSWER
Answered 2021-Mar-01 at 15:242-5 Mb
is probably not a size to worry about. The problem could appear when files are in 1-2Gb
size. Although you may face some out of memory when several concurrent uploads happens to your service.
The InputStreamResource
is just a decorator around an InputStream
with Resource
API for access to the underlying delegating stream. It is not clear how it can work in async environment since MultipartFile
is deleted in the end of HTTP upload request.
Plus you don't show any code to understand the situation better...
QUESTION
I want to simulate an async python3.5 function similar to what we have in Java with the SpringBoot @EnableAsync @Async annotation.
In Spring, methods annotated with the @Async annotation, control is returned to the previous method soon after the method invocation.
...ANSWER
Answered 2020-Jun-09 at 15:26Use threading.Thread(target=self.print_cpu_data)
, not threading.Thread(target=self.print_cpu_data())
- note that the parenthesis are removed. What you have now is explicitly calling print_cpu_data()
in the main thread, rather than sending it off to the background thread to be called. So your program never even gets to create/start the Thread
object.
QUESTION
Personal knowlegedment: I read from javacodegeeks: "... SimpleAsyncTaskExecutor is ok for toy projects but for anything larger than that it’s a bit risky since it does not limit concurrent threads and does not reuse threads. So to be safe, we will also add a task executor bean... " and from baeldung a very simple example how to add our own Task Executor. But I can find any guidance explaining what are the consequences and some worth cases to apply it.
Personal desire: I am working hard to provide a corporative architecture for our microservices logs be publish on Kafka topics. It seems reasonble the statement " risky caused by not limit concurrent threads and not reuse it" mainly for my case that is based on logs.
I am running the bellow code succesfully in local desktop but I am wondering if I am providing a custom Task Executor properly.
My question: does this configuration bellow taking in account I am already using kafkatempla (i.e. syncronized, singleton and thread safe by default at least for producing/sending messsage as far as understand it) really going in right direction to reuse threads and avoid spread accidentally threads creation while using SimpleAsyncTaskExecutor?
Producer config
...ANSWER
Answered 2020-Feb-27 at 08:24This is default implementation of SimpleAsyncTaskExecutor
QUESTION
@Bean
RabbitTemplate rabbitTemplate() {
RabbitTemplate template = new RabbitTemplate(rabbitConnectionFactory());
template.setMessageConverter(messageConverter);
template.setExchange(amqpProperties.getRabbitMqTopicExchangeName());
return template;
}
@Bean
@Conditional (OperationsCondition.class)
SimpleMessageListenerContainer opsMessageListenerContainer() {
return listenerContainer(amqpProperties.getRabbitMqOperationsQueue(),
amqpProperties.getInitialRabbitOperationsConsumerCount(),
amqpProperties.getMaximumRabbitOperationsConsumerCount(),
opsReceiver());
}
@Bean
@Conditional (OperationsCondition.class)
OperationsListener opsReceiver() {
return new OperationsListener();
}
private SimpleMessageListenerContainer listenerContainer(String queue,
int initConsumers,int maxConsumers, MessageListener listener)
{
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(rabbitConnectionFactory());
container.setQueueNames(queue);
container.setMessageListener(listener);
container.setConcurrentConsumers(initConsumers);
container.setMaxConcurrentConsumers(maxConsumers);
container.setMessageConverter(messageConverter);
return container;
}
...ANSWER
Answered 2019-Mar-26 at 14:24To confirm what you have found, this is clearly documented in the reference manual section "Exception Handling".
QUESTION
I want to be able to process more than 10 SQS messages at a time using a Spring Integration Workflow.
From this question, the recommendation was to use an ExecutorChannel. I updated my code but still have the same symptoms.
After making this update, my application requests 10 messages, processes those, and only after I make the call to amazonSQSClient.deleteMessage near the end of the flow will it accept another 10 messages from the SQS queue.
The application uses an SQS FiFo queue.
Is there something else I'm missing, or is this an unavoidable symptom of using SqsMessageDeletionPolicy.NEVER and then deleting the messages at the end of the flow? Accepting the messages at the beginning of the flow isn't really an option due to other constraints.
Here are the relevant snippets of code, with some simplifications, but I hope it expresses the problem.
Queue configuration
...ANSWER
Answered 2018-Sep-17 at 15:11I thought I'd post this as an answer, as this solves my issue, and may help others. As an answer it's more likely to get spotted rather than an edit to the original question that might get overlooked.
Firstly, I should have noted that we're using a FiFo queue.
The issue was actually further up the chain, where we were setting the MessageGroupId to a simple value that described the source of the data. This meant we had very large message groups.
From the ReceiveMessage documentation you can see that it quite sensibly stops you requesting more messages from that group in this scenario, as it would be impossible to guarantee the order should a message need to be put back on the queue.
Updating the code that posts the message to set an appropriate MessageGroupId then meant that the ExecutorChannel worked as expected.
While messages with a particular MessageGroupId are invisible, no more messages belonging to the same MessageGroupId are returned until the visibility timeout expires. You can still receive messages with another MessageGroupId as long as it is also visible.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install spring-async
You can use spring-async like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the spring-async component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page