本文整理汇总了Java中org.springframework.amqp.core.MessageListener类的典型用法代码示例。如果您正苦于以下问题:Java MessageListener类的具体用法?Java MessageListener怎么用?Java MessageListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageListener类属于org.springframework.amqp.core包,在下文中一共展示了MessageListener类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInvokeListener
import org.springframework.amqp.core.MessageListener; //导入依赖的package包/类
protected void doInvokeListener(MessageListener listener, Message message) throws Exception {
try {
serverRequestInterceptor.handle(new RabbitServerRequestAdapter(message));
listener.onMessage(message);
serverResponseInterceptor.handle(new RabbitServerResponseAdapter());
} catch (Exception e) {
throw wrapToListenerExecutionFailedExceptionIfNeeded(e, message);
}
}
示例2: replicationMessageListenerContainer
import org.springframework.amqp.core.MessageListener; //导入依赖的package包/类
@Bean
public MessageListenerContainer replicationMessageListenerContainer(
ConnectionFactory connectionFactory,
MessageListener replicationMessageListener
) {
DirectMessageListenerContainer container = new DirectMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueueNames(fullQueueName);
container.setMessageListener(replicationMessageListener);
return container;
}
示例3: messageListenerContainer
import org.springframework.amqp.core.MessageListener; //导入依赖的package包/类
@Bean
public MessageListenerContainer messageListenerContainer(
ConnectionFactory connectionFactory,
MessageListener messageListener
) {
DirectMessageListenerContainer container = new DirectMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueueNames(resultQueue);
container.setMessageListener(messageListener);
return container;
}
示例4: outMessageListenerContainer
import org.springframework.amqp.core.MessageListener; //导入依赖的package包/类
@Bean
public MessageListenerContainer outMessageListenerContainer(
ConnectionFactory outConnectionFactory,
MessageListener outMessageListener
) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(outConnectionFactory);
container.setQueueNames(resultQueue);
container.setMessageListener(outMessageListener);
return container;
}
示例5: fileServerMessageListenerContainer
import org.springframework.amqp.core.MessageListener; //导入依赖的package包/类
@Bean
public MessageListenerContainer fileServerMessageListenerContainer(
ConnectionFactory serverConnectionFactory,
MessageListener fileServerMessageListener
) {
DirectMessageListenerContainer container = new DirectMessageListenerContainer();
container.setConnectionFactory(serverConnectionFactory);
container.setQueueNames(fileQueue);
container.setMessageListener(fileServerMessageListener);
return container;
}
示例6: onMessage
import org.springframework.amqp.core.MessageListener; //导入依赖的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;
}
}
}
示例7: MessageListenerProxy
import org.springframework.amqp.core.MessageListener; //导入依赖的package包/类
public MessageListenerProxy(MessageListener listener, String jobName) {
this.delegate = listener;
this.jobName = jobName;
}
示例8: replicationMessageListener
import org.springframework.amqp.core.MessageListener; //导入依赖的package包/类
@Bean
public MessageListener replicationMessageListener(ReplicationComponent replicationComponent) {
return replicationComponent;
}
示例9: messageListener
import org.springframework.amqp.core.MessageListener; //导入依赖的package包/类
@Bean
public MessageListener messageListener(AvNetworkComponent avNetworkComponent) {
return avNetworkComponent;
}
示例10: outMessageListener
import org.springframework.amqp.core.MessageListener; //导入依赖的package包/类
@Bean
public MessageListener outMessageListener(AvNetworkComponent outComponent) {
return outComponent;
}
示例11: fileServerMessageListener
import org.springframework.amqp.core.MessageListener; //导入依赖的package包/类
@Bean
public MessageListener fileServerMessageListener(AvNetworkComponent fileAvNetworkComponent) {
return fileAvNetworkComponent;
}
示例12: newMessageListenerAdapter
import org.springframework.amqp.core.MessageListener; //导入依赖的package包/类
public MessageListenerAdapter newMessageListenerAdapter(MessageListener messageListener) {
return new MessageListenerAdapter(messageListener, messageConverter);
}