本文整理匯總了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;
}
}
}