Skip to content

Commit

Permalink
Well-known names for beans in message broker XML config
Browse files Browse the repository at this point in the history
Issue: SPR-15068
  • Loading branch information
rstoyanchev committed Jan 17, 2017
1 parent fcead67 commit 75daf78
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -104,6 +104,10 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {

public static final String SOCKJS_SCHEDULER_BEAN_NAME = "messageBrokerSockJsScheduler";

public static final String MESSAGING_TEMPLATE_BEAN_NAME = "brokerMessagingTemplate";

public static final String MESSAGE_CONVERTER_BEAN_NAME = "brokerMessageConverter";

private static final int DEFAULT_MAPPING_ORDER = 1;

private static final boolean jackson2Present = ClassUtils.isPresent(
Expand Down Expand Up @@ -482,7 +486,9 @@ private RuntimeBeanReference registerMessageConverter(Element element, ParserCon
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addIndexedArgumentValue(0, converters);
RootBeanDefinition messageConverterDef = new RootBeanDefinition(CompositeMessageConverter.class, cavs, null);
return new RuntimeBeanReference(registerBeanDef(messageConverterDef, context, source));
String name = MESSAGE_CONVERTER_BEAN_NAME;
registerBeanDefByName(name, messageConverterDef, context, source);
return new RuntimeBeanReference(name);
}

private RuntimeBeanReference registerMessagingTemplate(Element element, RuntimeBeanReference brokerChannel,
Expand All @@ -495,7 +501,9 @@ private RuntimeBeanReference registerMessagingTemplate(Element element, RuntimeB
beanDef.getPropertyValues().add("userDestinationPrefix", element.getAttribute("user-destination-prefix"));
}
beanDef.getPropertyValues().add("messageConverter", messageConverter);
return new RuntimeBeanReference(registerBeanDef(beanDef,context, source));
String name = MESSAGING_TEMPLATE_BEAN_NAME;
registerBeanDefByName(name, beanDef, context, source);
return new RuntimeBeanReference(name);
}

private void registerAnnotationMethodMessageHandler(Element messageBrokerElement,
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -333,10 +333,12 @@ public void annotationMethodMessageHandler() {
assertNotNull(messageConverter);
assertTrue(messageConverter instanceof CompositeMessageConverter);

CompositeMessageConverter compositeMessageConverter = this.appContext.getBean(CompositeMessageConverter.class);
String name = MessageBrokerBeanDefinitionParser.MESSAGE_CONVERTER_BEAN_NAME;
CompositeMessageConverter compositeMessageConverter = this.appContext.getBean(name, CompositeMessageConverter.class);
assertNotNull(compositeMessageConverter);

SimpMessagingTemplate simpMessagingTemplate = this.appContext.getBean(SimpMessagingTemplate.class);
name = MessageBrokerBeanDefinitionParser.MESSAGING_TEMPLATE_BEAN_NAME;
SimpMessagingTemplate simpMessagingTemplate = this.appContext.getBean(name, SimpMessagingTemplate.class);
assertNotNull(simpMessagingTemplate);
assertEquals("/personal/", simpMessagingTemplate.getUserDestinationPrefix());

Expand Down

0 comments on commit 75daf78

Please sign in to comment.