2015-01-31 2 views
0

Кто-нибудь знает, как получить атрибуты сообщения SQS с помощью Camel DSL в java? Я получаю следующее сообщение об ошибке:получать атрибуты сообщения sqs с помощью camel dsl?

"Failed to create route payee route: Route(batch route)[[From[aws-sqs://myqueue?amazonSQSEndpoint=... because of Failed to resolve endpoint: aws-sqs://myqueue?amazonSQSEndpoint=sqs.us-west-1.amazonaws.com&accessKey=*****&secretKey=****************&maxMessagesPerPoll=1&messageAttributeNames=%5BuserID%5 due to: Could not find a suitable setter for property: messageAttributeNames as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: java.util.Collection with value [userID] "

Пожалуйста найти мой код

StringBuilder QueueURI = new StringBuilder(); 
QueueURI(PropertyUtils.AWS_SQS) 
     .append(propertyUtils.queueName) 
     .append(PropertyUtils.AMAZON_SQS_REGION) 
     .append(propertyUtils.sqsRegion); 
QueueURI(PropertyUtils.AWS_ACCESS_KEY).append(
     propertyUtils.awsAccessKey); 
QueueURI(PropertyUtils.AWS_SECRET_KEY).append(
     propertyUtils.awsSecretKey); 
QueueURI(PropertyUtils.MAX_MESSAGES_PER_POLL_1); 
QueueURI("&messageAttributeNames="); 


Collection<String> collection = new ArrayList<String>(); 
collection.add("userID"); 

//aws-sqs://myqueue?amazonSQSEndpoint=sqs.us-west-1.amazonaws.com&accessKey=*****&secretKey=****************&maxMessagesPerPoll=1&messageAttributeNames=[userID] 

from(QueueURI.ToString() + collection) 
     .routeId("batch route") 
     .process(userValidator); 

ответ

0

Вы можете найти атрибуты ваших SQS сообщений в заголовке под названием CamelAwsSqsAttributes, как описано здесь: http://camel.apache.org/aws-sqs.html

Этот заголовок является Map<String, String>, который содержит то, что вы ищете. Если вы хотите, чтобы увидеть их, вы можете сделать что-то вроде:

... 
from(QueueURI.ToString() + collection) 
    .routeId("batch route") 
    .log("Attributes: ${header.CamelAwsSqsAttributes}") 
    .process(userValidator); 
+0

Мой вопрос заключается в том, чтобы установить messageAttributeNames = [USERID] в request url ... – Naveenkumar

+0

Один из способов - создать публичную коллекцию @Bean sqsAttributeNames() {} и добавить & messageAttributeNames = # sqsAttributeNames к адресу sqs url – user1573133

1

Camel не имеет java.lang.String => java.util.Collection TypeConverter по умолчанию. Вы можете реализовать org.apache.camel.TypeConverter, который затем может быть зарегистрирован с помощью TypeConverterRegistry CamelContext.

Я использую Spring, так что я мобилизует поддержку преобразования в Spring:

import org.apache.camel.Exchange; 
import org.apache.camel.TypeConversionException; 
import org.apache.camel.support.TypeConverterSupport; 
import org.springframework.core.convert.ConversionService; 
import org.springframework.core.convert.support.DefaultConversionService; 

public class TypeConverterBridge extends TypeConverterSupport { 
    private ConversionService cs = new DefaultConversionService(); 

    @Override 
    public <T> T convertTo(Class<T> type, Exchange exchange, Object value) throws TypeConversionException { 
     if (cs.canConvert(value.getClass(), type)) { 
      return cs.convert(value, type); 
     } 
     return null; 
    } 
} 

А потом зарегистрировал TypeConverter с моим CamelContext:

camelContext.getTypeConverterRegistry().addFallbackTypeConverter(new TypeConverterBridge(), false); 
Смежные вопросы