当前位置: 首页>>代码示例>>Java>>正文


Java MessageConverter类代码示例

本文整理汇总了Java中org.springframework.jms.support.converter.MessageConverter的典型用法代码示例。如果您正苦于以下问题:Java MessageConverter类的具体用法?Java MessageConverter怎么用?Java MessageConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MessageConverter类属于org.springframework.jms.support.converter包,在下文中一共展示了MessageConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getConverterByConverterName

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
protected MessageConverter getConverterByConverterName(String converterName) {

        try {
            Class<?> converterClass = ClassUtils.forName(converterName, this.beanClassLoader);
            for (JmsMessageConverter converter : messageConverters) {
                if (ClassUtils.isAssignableValue(converterClass, converter)) {
                    return converter;
                }
            }
        } catch (Throwable ex) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.warn("NOT FOUND the converter named {}", converterName);
            }
            LOGGER.warn("NOT FOUND the converter named {}", converterName, ex);
        }
        return defaultMessageConverter;
    }
 
开发者ID:kinglcc,项目名称:spring-boot-jms,代码行数:18,代码来源:GenericJmsMessageConverter.java

示例2: buildMessage

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
/**
 * Build a JMS message to be sent as response based on the given result object.
 * @param session the JMS Session to operate on
 * @param result the content of the message, as returned from the listener method
 * @return the JMS {@code Message} (never {@code null})
 * @throws JMSException if thrown by JMS API methods
 * @see #setMessageConverter
 */
protected Message buildMessage(Session session, Object result) throws JMSException {
	Object content = (result instanceof JmsResponse ? ((JmsResponse<?>) result).getResponse() : result);
	if (content instanceof org.springframework.messaging.Message) {
		return this.messagingMessageConverter.toMessage(content, session);
	}

	MessageConverter converter = getMessageConverter();
	if (converter != null) {
		return converter.toMessage(content, session);
	}

	if (!(content instanceof Message)) {
		throw new MessageConversionException(
				"No MessageConverter specified - cannot handle message [" + content + "]");
	}
	return (Message) content;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:AbstractAdaptableMessageListener.java

示例3: syncRetrieve

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public T syncRetrieve() throws Exception
{
	if (logger.isDebugEnabled())
	{
		Message msg = this.getTemplateConsumer().receive();

		logger.debug("***** SYNC CONSUMING MESSAGE******");
		traceMessage(msg);

		MessageConverter mc = ((IJMSServiceConsumer<?>) this).getTemplateConsumer()
				.getMessageConverter();
		return (T) mc.fromMessage(msg);
	}
	else
		return (T) ((IJMSServiceConsumer<?>) this).getTemplateConsumer()
				.receiveAndConvert();
}
 
开发者ID:Appverse,项目名称:appverse-server,代码行数:20,代码来源:JMSSyncService.java

示例4: jacksonJmsMessageConverter

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Bean
public MessageConverter jacksonJmsMessageConverter() {
    MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
    converter.setTargetType(MessageType.TEXT);
    converter.setTypeIdPropertyName("_type");
    return converter;
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:8,代码来源:JmsConfig.java

示例5: jacksonJmsMessageConverter

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Bean // Serialize message content to json using TextMessage
public MessageConverter jacksonJmsMessageConverter() {
    MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
    converter.setTargetType(MessageType.TEXT);
    converter.setTypeIdPropertyName("_type");
    return converter;
}
 
开发者ID:ftsakiris,项目名称:async-engine,代码行数:8,代码来源:Application.java

示例6: toMessage

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Override
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
    MessageConverter converter = getMessageConverterTo(object);
    Message message = converter.toMessage(object, session);
    setConverterOnMessage(message, converter);
    return message;
}
 
开发者ID:kinglcc,项目名称:spring-boot-jms,代码行数:8,代码来源:GenericJmsMessageConverter.java

示例7: getMessageConverterTo

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
private MessageConverter getMessageConverterTo(Object object) {
    for (JmsMessageConverter converter : messageConverters) {
        if (converter.canConvertTo(object)) {
            return converter;
        }
    }
    return defaultMessageConverter;
}
 
开发者ID:kinglcc,项目名称:spring-boot-jms,代码行数:9,代码来源:GenericJmsMessageConverter.java

示例8: getMessageConverterFrom

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
private MessageConverter getMessageConverterFrom(Message message) throws JMSException {
    String converterName = message.getStringProperty(CONVERTER_PROP);
    if (StringUtils.isNotBlank(converterName)) {
        return getConverterByConverterName(converterName);
    }
    for (JmsMessageConverter converter : messageConverters) {
        if (converter.canConvertFrom(message)) {
            return converter;
        }
    }
    return defaultMessageConverter;
}
 
开发者ID:kinglcc,项目名称:spring-boot-jms,代码行数:13,代码来源:GenericJmsMessageConverter.java

示例9: jacksonJmsMessageConverter

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Bean // Serialize message content to json using TextMessage
public MessageConverter jacksonJmsMessageConverter() {
	MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
	converter.setTargetType(MessageType.TEXT);
	converter.setTypeIdPropertyName("_type");
	return converter;
}
 
开发者ID:wallerlab,项目名称:reaktor,代码行数:8,代码来源:Config.java

示例10: extractMessage

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
/**
 * Extract the message body from the given JMS message.
 * @param message the JMS {@code Message}
 * @return the content of the message, to be passed into the listener method
 * as an argument
 * @throws MessageConversionException if the message could not be extracted
 */
protected Object extractMessage(Message message)  {
	try {
		MessageConverter converter = getMessageConverter();
		if (converter != null) {
			return converter.fromMessage(message);
		}
		return message;
	}
	catch (JMSException ex) {
		throw new MessageConversionException("Could not convert JMS message", ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:AbstractAdaptableMessageListener.java

示例11: createMessageForPayload

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Override
protected Message createMessageForPayload(Object payload, Session session) throws JMSException {
	MessageConverter converter = getMessageConverter();
	if (converter != null) {
		return converter.toMessage(payload, session);
	}
	throw new IllegalStateException("No message converter - cannot handle [" + payload + "]");
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:AbstractAdaptableMessageListener.java

示例12: getMessageConverter

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Override
public MessageConverter getMessageConverter() {
	JmsActivationSpecConfig config = getActivationSpecConfig();
	if (config != null) {
		return config.getMessageConverter();
	}
	return null;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:JmsMessageEndpointManager.java

示例13: createMessageListener

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Override
protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) {
	Assert.state(this.messageHandlerMethodFactory != null,
			"Could not create message listener - MessageHandlerMethodFactory not set");
	MessagingMessageListenerAdapter messageListener = createMessageListenerInstance();
	InvocableHandlerMethod invocableHandlerMethod =
			this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod());
	messageListener.setHandlerMethod(invocableHandlerMethod);
	String responseDestination = getDefaultResponseDestination();
	if (StringUtils.hasText(responseDestination)) {
		if (container.isReplyPubSubDomain()) {
			messageListener.setDefaultResponseTopicName(responseDestination);
		}
		else {
			messageListener.setDefaultResponseQueueName(responseDestination);
		}
	}
	MessageConverter messageConverter = container.getMessageConverter();
	if (messageConverter != null) {
		messageListener.setMessageConverter(messageConverter);
	}
	DestinationResolver destinationResolver = container.getDestinationResolver();
	if (destinationResolver != null) {
		messageListener.setDestinationResolver(destinationResolver);
	}
	return messageListener;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:28,代码来源:MethodJmsListenerEndpoint.java

示例14: getRequiredMessageConverter

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
private MessageConverter getRequiredMessageConverter() throws IllegalStateException {
	MessageConverter converter = getMessageConverter();
	if (converter == null) {
		throw new IllegalStateException("No 'messageConverter' specified. Check configuration of JmsTemplate.");
	}
	return converter;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:JmsTemplate.java

示例15: incomingMessageUsesMessageConverter

import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Test
public void incomingMessageUsesMessageConverter() throws JMSException {
	javax.jms.Message jmsMessage = mock(javax.jms.Message.class);
	Session session = mock(Session.class);
	MessageConverter messageConverter = mock(MessageConverter.class);
	given(messageConverter.fromMessage(jmsMessage)).willReturn("FooBar");
	MessagingMessageListenerAdapter listener = getSimpleInstance("simple", Message.class);
	listener.setMessageConverter(messageConverter);
	listener.onMessage(jmsMessage, session);
	verify(messageConverter, times(1)).fromMessage(jmsMessage);
	assertEquals(1, sample.simples.size());
	assertEquals("FooBar", sample.simples.get(0).getPayload());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:MessagingMessageListenerAdapterTests.java


注:本文中的org.springframework.jms.support.converter.MessageConverter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。