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


Java MessageConverter类代码示例

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


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

示例1: stompClient

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(WebSocketStompClient.class)
public WebSocketStompClient stompClient(MessageConverter messageConverter,
                                        ThreadPoolTaskScheduler taskScheduler) {
    int bufferSizeLimit = 1024 * 1024 * 8;

    StandardWebSocketClient webSocketClient = new StandardWebSocketClient();
    List<Transport> transports = new ArrayList<>();
    transports.add(new WebSocketTransport(webSocketClient));
    SockJsClient sockJsClient = new SockJsClient(transports);
    WebSocketStompClient client = new WebSocketStompClient(sockJsClient);
    client.setInboundMessageSizeLimit(bufferSizeLimit);
    client.setMessageConverter(messageConverter);
    client.setTaskScheduler(taskScheduler);
    client.setDefaultHeartbeat(new long[]{0, 0});
    return client;
}
 
开发者ID:mthizo247,项目名称:spring-cloud-netflix-zuul-websocket,代码行数:18,代码来源:ZuulWebSocketConfiguration.java

示例2: SimpAnnotationMethodMessageHandler

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
/**
 * Create an instance of SimpAnnotationMethodMessageHandler with the given
 * message channels and broker messaging template.
 * @param clientInboundChannel the channel for receiving messages from clients (e.g. WebSocket clients)
 * @param clientOutboundChannel the channel for messages to clients (e.g. WebSocket clients)
 * @param brokerTemplate a messaging template to send application messages to the broker
 */
public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel,
		MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate) {

	Assert.notNull(clientInboundChannel, "clientInboundChannel must not be null");
	Assert.notNull(clientOutboundChannel, "clientOutboundChannel must not be null");
	Assert.notNull(brokerTemplate, "brokerTemplate must not be null");

	this.clientInboundChannel = clientInboundChannel;
	this.clientMessagingTemplate = new SimpMessagingTemplate(clientOutboundChannel);
	this.brokerTemplate = brokerTemplate;

	Collection<MessageConverter> converters = new ArrayList<MessageConverter>();
	converters.add(new StringMessageConverter());
	converters.add(new ByteArrayMessageConverter());
	this.messageConverter = new CompositeMessageConverter(converters);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:SimpAnnotationMethodMessageHandler.java

示例3: addRemoteRegistryDto

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
void addRemoteRegistryDto(Message<?> message, MessageConverter converter, long expirationPeriod) {
	UserRegistryDto registryDto = (UserRegistryDto) converter.fromMessage(message, UserRegistryDto.class);
	if (registryDto != null && !registryDto.getId().equals(this.id)) {
		long expirationTime = System.currentTimeMillis() + expirationPeriod;
		registryDto.setExpirationTime(expirationTime);
		registryDto.restoreParentReferences();
		this.remoteRegistries.put(registryDto.getId(), registryDto);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:MultiServerUserRegistry.java

示例4: configureMessageConvertersCustom

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
@Test
public void configureMessageConvertersCustom() {
	final MessageConverter testConverter = mock(MessageConverter.class);
	AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
		@Override
		protected boolean configureMessageConverters(List<MessageConverter> messageConverters) {
			messageConverters.add(testConverter);
			return false;
		}
	};

	CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
	assertThat(compositeConverter.getConverters().size(), Matchers.is(1));
	Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator();
	assertThat(iterator.next(), Matchers.is(testConverter));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:MessageBrokerConfigurationTests.java

示例5: configureMessageConvertersCustomAndDefault

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
@Test
public void configureMessageConvertersCustomAndDefault() {
	final MessageConverter testConverter = mock(MessageConverter.class);

	AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
		@Override
		protected boolean configureMessageConverters(List<MessageConverter> messageConverters) {
			messageConverters.add(testConverter);
			return true;
		}
	};
	CompositeMessageConverter compositeConverter = config.brokerMessageConverter();

	assertThat(compositeConverter.getConverters().size(), Matchers.is(4));
	Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator();
	assertThat(iterator.next(), Matchers.is(testConverter));
	assertThat(iterator.next(), Matchers.instanceOf(StringMessageConverter.class));
	assertThat(iterator.next(), Matchers.instanceOf(ByteArrayMessageConverter.class));
	assertThat(iterator.next(), Matchers.instanceOf(MappingJackson2MessageConverter.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:MessageBrokerConfigurationTests.java

示例6: sendHistoryToNewSubscriber

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
private void sendHistoryToNewSubscriber(AbstractSubProtocolEvent ev) {
    Message<byte[]> msg = ev.getMessage();
    StompHeaderAccessor ha = StompHeaderAccessor.wrap(msg);
    String pattern = ha.getDestination();
    if(!pattern.startsWith(PREFIX)) {
        // we must send only to appropriate paths
        return;
    }
    MessageConverter messageConverter = this.simpMessagingTemplate.getMessageConverter();

    for(BusData data: buses.values()) {
        String dest = getDestination(data.getId());
        if(!this.pathMatcher.match(pattern, dest)) {
            continue;
        }
        for(Object obj: data.getEvents()) {
            StompHeaderAccessor mha = Stomp.createHeaders(ha.getSessionId(), ha.getSubscriptionId());
            mha.setDestination(dest);
            Message<?> message = messageConverter.toMessage(obj, mha.getMessageHeaders());
            clientChannel.send(message);
        }
    }
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:24,代码来源:EventRouter.java

示例7: sqsMessageHandler

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
@Bean
public QueueMessageHandler sqsMessageHandler() {
  Collection<MessageConverter> converters = new ArrayList<>();
  MappingJackson2MessageConverter jacksonConverter = new MappingJackson2MessageConverter();
  jacksonConverter.setSerializedPayloadClass(String.class);
  jacksonConverter.setStrictContentTypeMatch(false);
  converters.add(jacksonConverter);

  List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
  CompositeMessageConverter compositeMessageConverter = new CompositeMessageConverter(converters);
  resolvers.add(new NotificationMessageArgumentResolver(compositeMessageConverter));
  resolvers.add(new PayloadArgumentResolver(compositeMessageConverter));

  QueueMessageHandler handler = sqsMessageHandlerFactory().createQueueMessageHandler();
  handler.setArgumentResolvers(resolvers);
  return handler;
}
 
开发者ID:kalnee,项目名称:trivor,代码行数:18,代码来源:AWSConfig.java

示例8: testConfigureOutputChannelWithBadContentType

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
@Test
public void testConfigureOutputChannelWithBadContentType() {
	BindingServiceProperties props = new BindingServiceProperties();
	BindingProperties bindingProps = new BindingProperties();
	bindingProps.setContentType("application/json");
	props.setBindings(Collections.singletonMap("foo", bindingProps));
	CompositeMessageConverterFactory converterFactory = new CompositeMessageConverterFactory(
			Collections.<MessageConverter>emptyList(), null);
	MessageConverterConfigurer configurer = new MessageConverterConfigurer(props, converterFactory);
	QueueChannel out = new QueueChannel();
	configurer.configureOutputChannel(out, "foo");
	out.send(new GenericMessage<Foo>(new Foo(),
			Collections.<String, Object> singletonMap(MessageHeaders.CONTENT_TYPE, "bad/ct")));
	Message<?> received = out.receive(0);
	assertThat(received).isNotNull();
	assertThat(received.getPayload()).isInstanceOf(Foo.class);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:18,代码来源:MessageConverterConfigurerTests.java

示例9: testConfigureInputChannelWithLegacyContentType

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
@Test
public void testConfigureInputChannelWithLegacyContentType() {
	BindingServiceProperties props = new BindingServiceProperties();
	BindingProperties bindingProps = new BindingProperties();
	bindingProps.setContentType("foo/bar");
	props.setBindings(Collections.singletonMap("foo", bindingProps));
	CompositeMessageConverterFactory converterFactory = new CompositeMessageConverterFactory(
			Collections.<MessageConverter>emptyList(), null);
	MessageConverterConfigurer configurer = new MessageConverterConfigurer(props, converterFactory);
	QueueChannel in = new QueueChannel();
	configurer.configureInputChannel(in, "foo");
	Foo foo = new Foo();
	in.send(
			MessageBuilder.withPayload(foo)
				.setHeader(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE, "application/json")
				.setHeader(BinderHeaders.SCST_VERSION, "1.x")
				.build());
	Message<?> received = in.receive(0);
	assertThat(received).isNotNull();
	assertThat(received.getPayload()).isEqualTo(foo);
	assertThat(received.getHeaders().get(MessageHeaders.CONTENT_TYPE).toString()).isEqualTo("application/json");
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:23,代码来源:MessageConverterConfigurerTests.java

示例10: userMessageConverter

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
@Bean
@StreamMessageConverter
public MessageConverter userMessageConverter() throws IOException {
	AvroSchemaMessageConverter avroSchemaMessageConverter = new AvroSchemaMessageConverter(
			MimeType.valueOf("avro/bytes"));
	if (schemaLocation != null) {
		avroSchemaMessageConverter.setSchemaLocation(schemaLocation);
	}
	return avroSchemaMessageConverter;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:11,代码来源:AvroSchemaMessageConverterTests.java

示例11: createPayloadArgumentCompositeConverter

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
private CompositeMessageConverter createPayloadArgumentCompositeConverter() {
    List<MessageConverter> payloadArgumentConverters = new ArrayList<>();

    if (JACKSON_2_PRESENT) {
        MappingJackson2MessageConverter jacksonMessageConverter = new MappingJackson2MessageConverter();
        jacksonMessageConverter.setObjectMapper(Jackson2ObjectMapperBuilder.json().build());
        jacksonMessageConverter.setSerializedPayloadClass(String.class);
        jacksonMessageConverter.setStrictContentTypeMatch(true);
        payloadArgumentConverters.add(jacksonMessageConverter);
    }

    ObjectMessageConverter objectMessageConverter = new ObjectMessageConverter();
    objectMessageConverter.setStrictContentTypeMatch(true);
    payloadArgumentConverters.add(objectMessageConverter);

    payloadArgumentConverters.add(new SimpleMessageConverter());

    return new CompositeMessageConverter(payloadArgumentConverters);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:20,代码来源:QueueMessageHandler.java

示例12: initMessageConverter

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
protected void initMessageConverter(MessageConverter messageConverter) {

        StringMessageConverter stringMessageConverter = new StringMessageConverter();
        stringMessageConverter.setSerializedPayloadClass(String.class);

        List<MessageConverter> messageConverters = new ArrayList<>();
        messageConverters.add(stringMessageConverter);

        if (messageConverter != null) {
            messageConverters.add(messageConverter);
        } else if (JACKSON_2_PRESENT) {
            MappingJackson2MessageConverter mappingJackson2MessageConverter = new MappingJackson2MessageConverter();
            mappingJackson2MessageConverter.setObjectMapper(Jackson2ObjectMapperBuilder.json().build());
            mappingJackson2MessageConverter.setSerializedPayloadClass(String.class);
            messageConverters.add(mappingJackson2MessageConverter);
        }

        setMessageConverter(new CompositeMessageConverter(messageConverters));
    }
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:20,代码来源:AbstractMessageChannelMessagingSendingTemplate.java

示例13: parseInternal_withCustomConverter_mustBeSetOnTemplate

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
@Test
public void parseInternal_withCustomConverter_mustBeSetOnTemplate() throws Exception {
    //Arrange
    DefaultListableBeanFactory registry = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry);

    //Act
    reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-custom-converter.xml", getClass()));

    //Assert
    QueueMessagingTemplate queueMessagingTemplateBeanDefinition = registry.getBean(QueueMessagingTemplate.class);
    MessageConverter messageConverter = queueMessagingTemplateBeanDefinition.getMessageConverter();
    assertTrue(CompositeMessageConverter.class.isInstance(messageConverter));
    CompositeMessageConverter compositeMessageConverter = (CompositeMessageConverter) messageConverter;
    assertEquals(2, compositeMessageConverter.getConverters().size());
    assertTrue(ObjectMessageConverter.class.isInstance(compositeMessageConverter.getConverters().get(1)));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:18,代码来源:QueueMessagingTemplateBeanDefinitionParserTest.java

示例14: bookingOrderMessageConverter

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
@Bean
public MessageConverter bookingOrderMessageConverter() throws IOException {
    LOG.info("avro message converter bean initialized.");
    AvroSchemaMessageConverter avroSchemaMessageConverter = new AvroSchemaMessageConverter(MimeType.valueOf("application/bookingOrder.v1+avro"));
    avroSchemaMessageConverter.setSchemaLocation(new ClassPathResource("avro/bookingOrder.avsc"));
    return avroSchemaMessageConverter;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Microservices-with-Java-9-Second-Edition,代码行数:8,代码来源:BookingApp.java

示例15: setMessageConverter

import org.springframework.messaging.converter.MessageConverter; //导入依赖的package包/类
/**
 * Configure a {@link MessageConverter} to use to convert the payload of a message from
 * its serialized form with a specific MIME type to an Object matching the target method
 * parameter. The converter is also used when sending a message to the message broker.
 * @see CompositeMessageConverter
 */
public void setMessageConverter(MessageConverter converter) {
	this.messageConverter = converter;
	if (converter != null) {
		((AbstractMessageSendingTemplate<?>) this.clientMessagingTemplate).setMessageConverter(converter);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:SimpAnnotationMethodMessageHandler.java


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