org.springframework.cloud.aws.messaging.listener.annotation.SqsListener Java Examples

The following examples show how to use org.springframework.cloud.aws.messaging.listener.annotation.SqsListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Sample2Listener.java    From spring-boot-aws-mock with MIT License 6 votes vote down vote up
@SqsListener(value = "sample2", deletionPolicy = SqsMessageDeletionPolicy.NEVER)
public void receive(String message, @Header("SenderId") String senderId, Acknowledgment ack) throws IOException {
    log.info("[sample2][Queue] senderId: {}, message: {}", senderId, message);
    PointDto messageObject = objectMapper.readValue(message, PointDto.class);
    pointRepository.save(messageObject.toEntity());
    ack.acknowledge();
    countDownLatch.countDown();
    log.info("[sample2] Success Ack");
}
 
Example #2
Source File: SpringCloudSQS.java    From tutorials with MIT License 5 votes vote down vote up
@SqsListener(QUEUE_NAME)
public void receiveMessage(String message, @Header("SenderId") String senderId) {
    logger.info("Received message: {}, having SenderId: {}", message, senderId);
    if (countDownLatch != null) {
        countDownLatch.countDown();
    }
}
 
Example #3
Source File: SqsController.java    From aws-refapp with Apache License 2.0 5 votes vote down vote up
@SqsListener(QUEUE_NAME)
private void receiveMessage(MessageToProcess message, @Header("ApproximateFirstReceiveTimestamp") String approximateFirstReceiveTimestamp) {
    LOG.debug("Received SQS message {}", message);

    try {
        this.sqsSendingTextWebSocketHandler.broadcastToSessions(new DataWithTimestamp<>(message, approximateFirstReceiveTimestamp));
    } catch (IOException e) {
        LOG.error("Was not able to push the message to the client.", e);
    }
}
 
Example #4
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@RuntimeUse
@SqsListener("testQueue")
public void receive(@NotificationSubject String subject,
		@NotificationMessage String message) {
	this.subject = subject;
	this.message = message;
}
 
Example #5
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@RuntimeUse
@SqsListener("testQueue")
public void receive(@Payload String payload,
		@Headers Map<String, String> headers) {
	this.payload = payload;
	this.headers = headers;
}
 
Example #6
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@RuntimeUse
@SqsListener("testQueue")
public void receive(@Payload String payload,
		@Header(value = "SenderId", required = false) String senderId) {
	this.senderId = senderId;
	this.payload = payload;
}
 
Example #7
Source File: SimpleMessageListenerContainerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@RuntimeUse
@SqsListener(value = "neverError",
		deletionPolicy = SqsMessageDeletionPolicy.NEVER)
private void neverError(String message, Acknowledgment acknowledgment) {
	this.countdownLatch.countDown();
	throw new RuntimeException("BOOM!");
}
 
Example #8
Source File: SimpleMessageListenerContainerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@RuntimeUse
@SqsListener(value = "noRedriveError",
		deletionPolicy = SqsMessageDeletionPolicy.NO_REDRIVE)
private void noRedriveError(String message) {
	this.countdownLatch.countDown();
	throw new RuntimeException("BOOM!");
}
 
Example #9
Source File: SimpleMessageListenerContainerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@RuntimeUse
@SqsListener(value = "onSuccessError",
		deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
private void onSuccessError(String message) {
	this.countdownLatch.countDown();
	throw new RuntimeException("BOOM!");
}
 
Example #10
Source File: SimpleMessageListenerContainerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@RuntimeUse
@SqsListener(value = "alwaysError",
		deletionPolicy = SqsMessageDeletionPolicy.ALWAYS)
private void alwaysError(String message) {
	this.countdownLatch.countDown();
	throw new RuntimeException("BOOM!");
}
 
Example #11
Source File: SimpleMessageListenerContainerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@RuntimeUse
@SqsListener(value = "testQueue",
		deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
private void manualSuccess(String message, Visibility visibility) {
	this.visibility = visibility;
	this.countDownLatch.countDown();
}
 
Example #12
Source File: QueueMessageHandler.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Override
protected MappingInformation getMappingForMethod(Method method,
		Class<?> handlerType) {
	SqsListener sqsListenerAnnotation = AnnotationUtils.findAnnotation(method,
			SqsListener.class);
	if (sqsListenerAnnotation != null && sqsListenerAnnotation.value().length > 0) {
		if (sqsListenerAnnotation.deletionPolicy() == SqsMessageDeletionPolicy.NEVER
				&& hasNoAcknowledgmentParameter(method.getParameterTypes())) {
			this.logger.warn("Listener method '" + method.getName() + "' in type '"
					+ method.getDeclaringClass().getName()
					+ "' has deletion policy 'NEVER' but does not have a parameter of type Acknowledgment.");
		}
		return new MappingInformation(
				resolveDestinationNames(sqsListenerAnnotation.value()),
				sqsListenerAnnotation.deletionPolicy());
	}

	MessageMapping messageMappingAnnotation = AnnotationUtils.findAnnotation(method,
			MessageMapping.class);
	if (messageMappingAnnotation != null
			&& messageMappingAnnotation.value().length > 0) {
		return new MappingInformation(
				resolveDestinationNames(messageMappingAnnotation.value()),
				SqsMessageDeletionPolicy.ALWAYS);
	}

	return null;
}
 
Example #13
Source File: Sample3Listener.java    From spring-boot-aws-mock with MIT License 5 votes vote down vote up
@SqsListener(value = "sample3", deletionPolicy = SqsMessageDeletionPolicy.NEVER)
public void receive(String message, @Header("SenderId") String senderId, Acknowledgment ack) throws IOException {
    log.info("[sample3][Queue] senderId: {}, message: {}", senderId, message);
    PointDto messageObject = objectMapper.readValue(message, PointDto.class);
    try{
        pointRepository.save(messageObject.toEntity());
        ack.acknowledge();
        countDownLatch.countDown();
        log.info("[sample3] Success Ack");
    } catch (Exception e){
        log.error("[sample3] Point Save Fail: "+ message, e);
    }
}
 
Example #14
Source File: NotificationMessagingTemplateIntegrationTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@RuntimeUse
@SqsListener("NotificationQueue")
private void messageListener(@NotificationSubject String subject,
		@NotificationMessage TestPerson message) {
	this.subject = subject;
	this.message = message;
	this.countDownLatch.countDown();
}
 
Example #15
Source File: QueueListenerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@RuntimeUse
@SqsListener("QueueListenerTest")
public void receiveMessage(String message,
		@Header(value = "SenderId", required = false) String senderId,
		@Headers Map<String, Object> allHeaders, SqsMessageHeaders asSqsHeaders) {
	LOGGER.debug("Received message with content {}", message);
	this.receivedMessages.add(message);
	this.senderId = senderId;
	this.allHeaders = allHeaders;
	this.approximateReceiveCount = asSqsHeaders.getApproximateReceiveCount();
	this.approximateFirstReceiveTimestamp = asSqsHeaders
			.getApproximateFirstReceiveTimestamp();
	this.timestamp = asSqsHeaders.getTimestamp();
	this.sentTimestamp = asSqsHeaders.getSentTimestamp();
	this.getCountDownLatch().countDown();
}
 
Example #16
Source File: QueueListenerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@RuntimeUse
@SqsListener("SendToQueue")
@SendTo("QueueListenerTest")
public String receiveMessage(String message) {
	LOGGER.debug("Received message with content {}", message);
	this.receivedMessages.add(message);
	return message.toUpperCase();
}
 
Example #17
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@RuntimeUse
@SqsListener
public void receive() {

}
 
Example #18
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@RuntimeUse
@SqsListener("#{environment.myQueue}")
public void receive(String value) {
	this.lastReceivedMessage = value;
}
 
Example #19
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@RuntimeUse
@SqsListener("${custom.queueName}")
public void receive(String value) {
	this.lastReceivedMessage = value;
}
 
Example #20
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@RuntimeUse
@SqsListener("testQueue")
public void receive(DummyKeyValueHolder value) {
	this.lastReceivedMessage = value;
}
 
Example #21
Source File: SampleListener.java    From spring-boot-aws-mock with MIT License 4 votes vote down vote up
@SqsListener(value = "sample", deletionPolicy = SqsMessageDeletionPolicy.NEVER)
public void receive(String message, @Header("SenderId") String senderId, Acknowledgment ack) throws IOException, ExecutionException, InterruptedException {
    log.info("senderId: {}, message: {}", senderId, message);
    ack.acknowledge();
    countDownLatch.countDown();
}
 
Example #22
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@RuntimeUse
@SqsListener("testQueue")
public void receive(@Payload String payload, SqsMessageHeaders headers) {
	this.payload = payload;
	this.headers = headers;
}
 
Example #23
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@RuntimeUse
@SqsListener("testQueue")
public void receive(@Payload String payload, MessageHeaders headers) {
	this.payload = payload;
	this.headers = headers;
}
 
Example #24
Source File: Sample3Listener.java    From spring-boot-aws-mock with MIT License 4 votes vote down vote up
@SqsListener(value = "sample3-dlq")
public void receiveDlq(String message) throws IOException {
    log.info("[sample3][DLQ]  message: {}", message);
    countDownLatch.countDown();
}
 
Example #25
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@SqsListener("receive")
public String receive(String value) {
	throw new RuntimeException("test exception");
}
 
Example #26
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@RuntimeUse
@SqsListener("testQueue")
public void receive(String message) {
}
 
Example #27
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@RuntimeUse
@SqsListener(value = "testQueue", deletionPolicy = SqsMessageDeletionPolicy.NEVER)
public void receive(String message) {
}
 
Example #28
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@RuntimeUse
@SqsListener("#{'queueOne,queueTwo'.split(',')}")
public void receive(String message) {
}
 
Example #29
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@RuntimeUse
@SqsListener("testQueue")
public void receive(Message<DummyKeyValueHolder> value) {
	this.lastReceivedMessage = value;
}
 
Example #30
Source File: MessageListenerContainerTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "UnusedDeclaration", "EmptyMethod" })
@SqsListener("testQueue")
void listenerMethod(String ignore) {

}