本文整理汇总了Java中org.springframework.amqp.AmqpIllegalStateException类的典型用法代码示例。如果您正苦于以下问题:Java AmqpIllegalStateException类的具体用法?Java AmqpIllegalStateException怎么用?Java AmqpIllegalStateException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AmqpIllegalStateException类属于org.springframework.amqp包,在下文中一共展示了AmqpIllegalStateException类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateCustomer
import org.springframework.amqp.AmqpIllegalStateException; //导入依赖的package包/类
@RabbitListener(queues = {"customer.update"})
public void updateCustomer(String message) throws InterruptedException, IOException {
Profile profile = objectMapper.readValue(message, Profile.class);
try {
// Update the customer service for the profile
UpdateCustomerResponse response =
customerClient.updateCustomerResponse(profile);
if (!response.isSuccess()) {
String errorMsg =
String.format("Could not update customer from profile for %s",
profile.getUsername());
log.error(errorMsg);
throw new UnexpectedException(errorMsg);
}
} catch (Exception ex) {
// Throw AMQP exception and redeliver the message
throw new AmqpIllegalStateException("Customer service update failed", ex);
}
}
示例2: onMessage
import org.springframework.amqp.AmqpIllegalStateException; //导入依赖的package包/类
@Override
public void onMessage(Message message, Channel channel) throws Exception {
// Check whether the delegate is a MessageListener impl itself.
// In that case, the adapter will simply act as a pass-through.
Object delegate = getDelegate();
if (delegate != this) {
if (delegate instanceof ChannelAwareMessageListener) {
if (channel != null) {
((ChannelAwareMessageListener) delegate).onMessage(message, channel);
return;
} else if (!(delegate instanceof MessageListener)) {
throw new AmqpIllegalStateException(
"MessageListenerAdapter cannot handle a "
+ "ChannelAwareMessageListener delegate if it hasn't been invoked with a Channel itself");
}
}
if (delegate instanceof MessageListener) {
((MessageListener) delegate).onMessage(message);
return;
}
}
String methodName = getListenerMethodName(message, null);
if (methodName == null) {
throw new AmqpIllegalStateException("No default listener method specified: "
+ "Either specify a non-null value for the 'defaultListenerMethod' property or "
+ "override the 'getListenerMethodName' method.");
}
Method[] methods = delegate.getClass().getMethods();
for (Method method : methods) {
if (method.getName().equals(methodName) && method.getParameterTypes().length == 1) {
Class<?> clazz = method.getParameterTypes()[0];
String className = clazz.getName();
setMessageHeader(message.getMessageProperties(),
AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME, className);
// 泛型的参数类型
Type[] types = method.getGenericParameterTypes();
// 存在泛型
if (types.length >= 0 && types[0] instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType) types[0];
// 泛型
Type[] actualTypeArguments = pType.getActualTypeArguments();
if (Collection.class.isAssignableFrom(clazz) && actualTypeArguments.length == 1) {
// collection
setListMessageHeader(message.getMessageProperties(), actualTypeArguments[0]);
} else if (Map.class.isAssignableFrom(clazz) && actualTypeArguments.length == 2) {
// map
setMapMessageHeader(message.getMessageProperties(), actualTypeArguments);
}
}
Object convertedMessage = extractMessage(message);
Object result = method.invoke(delegate, convertedMessage);
if (result != null) {
handleResult(result, message, channel);
}
return;
}
}
}