'How to identify that an SQS-Queue does not exist?
I would expect that if the SQS queue specified in the following annotation does not exist, Spring will throw a NonExistentQueue exception at start time.
@SqsListener(value = "nonExistingQueue", deletionPolicy = SqsMessageDeletionPolicy.ALWAYS)
But somehow no exception is thrown in my case and the application will be started without the queue. Why will be no exception thrown? May it be disabled somehow? Sorry, I am pretty new to AWS. My goal is that my application couldn't even start without a queue present. If an exception were thrown would it suffice, or maybe I need to create an @PostConstruct method that checks for existence and manually throws an exception?
My properties:
cloud.aws.credentials.access-key=accesKey
cloud.aws.credentials.secret-key=secretKey
cloud.aws.region.auto=false
cloud.aws.region.static=eu-central-1
cloud.aws.stack.auto=false
When I create the SQS-Queue that SqlListened needs, the application works fine. Here is my pom to check out my dependencies:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.792</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-autoconfigure</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-context</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-messaging</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
Thank you very much.
Solution 1:[1]
I've requested this feature in spring-cloud-aws project: https://github.com/awspring/spring-cloud-aws/issues/393
just c/p my workaround here:
- Custom destination resolver that throws
RuntimeExceptionthat will not be catched bySimpleMessageListenerContainer:
public class FailingDestinationResolver<T> implements DestinationResolver<T> {
private final DestinationResolver<T> destinationResolver;
public FailingDestinationResolver(DestinationResolver<T> destinationResolver) {
this.destinationResolver = destinationResolver;
}
@Override
public T resolveDestination(String name) {
try {
return destinationResolver.resolveDestination(name);
} catch (DestinationResolutionException e) {
throw new RuntimeException("Fail to resolve '" + name + "' destination", e);
}
}
}
- Configure
SimpleMessageListenerContainerFactorybean with custom queue resolver:
@Bean
public SimpleMessageListenerContainerFactory sqsListenerContainerFactory(DestinationResolver<String> queueDestinationResolver) {
SimpleMessageListenerContainerFactory factory = new SimpleMessageListenerContainerFactory();
factory.setDestinationResolver(queueDestinationResolver);
return factory;
}
@Bean
public DestinationResolver<String> queueDestinationResolver(AmazonSQSAsync sqs) {
return new CachingDestinationResolverProxy<>(new FailingDestinationResolver<>(new DynamicQueueUrlDestinationResolver(sqs, null)));
}
Note that spring cloud.aws.sqs.listener.* properties ignored for this configuration, additional code is required to pick them up from SqsProperties.
Solution 2:[2]
Try this in the fetch:
fetch(process.env.REACT_APP_API+`User/${id}`,{
method:'GET',
header:{'Accept':'application/json',
'Content-Type':'application/json'}
})
Notice to " ` " around URL.
Tell me, did it help you?
Solution 3:[3]
In a React class component, you can access the parameters using this.props.location.search.
You can parse the result like so:
new URLSearchParams(this.props.location.search).get("id")
I would not try to access React hooks (like useParams) in a class component. The purpose of hooks in React is to provide state and lifecycle methods to functional components, but class components already have these things.
You are creating a functional component (UserInfo) purely so that you can call a hook so that you can access state that your class component already has access to.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aleksey Krichevskiy |
| Solution 2 | Arman Ebrahimi |
| Solution 3 |
