Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
42e0dc14
Commit
42e0dc14
authored
Sep 23, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate from deprecated Artemis EmbeddedJMS
Closes gh-16646
parent
b210d2fc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
18 deletions
+32
-18
ArtemisEmbeddedServerConfiguration.java
...igure/jms/artemis/ArtemisEmbeddedServerConfiguration.java
+23
-10
ArtemisAutoConfigurationTests.java
...oconfigure/jms/artemis/ArtemisAutoConfigurationTests.java
+9
-8
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisEmbeddedServerConfiguration.java
View file @
42e0dc14
...
@@ -19,13 +19,16 @@ package org.springframework.boot.autoconfigure.jms.artemis;
...
@@ -19,13 +19,16 @@ package org.springframework.boot.autoconfigure.jms.artemis;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
org.apache.activemq.artemis.api.core.RoutingType
;
import
org.apache.activemq.artemis.core.config.CoreAddressConfiguration
;
import
org.apache.activemq.artemis.core.config.CoreQueueConfiguration
;
import
org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ
;
import
org.apache.activemq.artemis.jms.server.config.JMSConfiguration
;
import
org.apache.activemq.artemis.jms.server.config.JMSConfiguration
;
import
org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration
;
import
org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration
;
import
org.apache.activemq.artemis.jms.server.config.TopicConfiguration
;
import
org.apache.activemq.artemis.jms.server.config.TopicConfiguration
;
import
org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl
;
import
org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl
;
import
org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationImpl
;
import
org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationImpl
;
import
org.apache.activemq.artemis.jms.server.config.impl.TopicConfigurationImpl
;
import
org.apache.activemq.artemis.jms.server.config.impl.TopicConfigurationImpl
;
import
org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
...
@@ -42,7 +45,7 @@ import org.springframework.context.annotation.Configuration;
...
@@ -42,7 +45,7 @@ import org.springframework.context.annotation.Configuration;
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
@Configuration
(
proxyBeanMethods
=
false
)
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnClass
(
Embedded
JMS
.
class
)
@ConditionalOnClass
(
Embedded
ActiveMQ
.
class
)
@ConditionalOnProperty
(
prefix
=
"spring.artemis.embedded"
,
name
=
"enabled"
,
havingValue
=
"true"
,
@ConditionalOnProperty
(
prefix
=
"spring.artemis.embedded"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
matchIfMissing
=
true
)
class
ArtemisEmbeddedServerConfiguration
{
class
ArtemisEmbeddedServerConfiguration
{
...
@@ -61,15 +64,25 @@ class ArtemisEmbeddedServerConfiguration {
...
@@ -61,15 +64,25 @@ class ArtemisEmbeddedServerConfiguration {
@Bean
(
initMethod
=
"start"
,
destroyMethod
=
"stop"
)
@Bean
(
initMethod
=
"start"
,
destroyMethod
=
"stop"
)
@ConditionalOnMissingBean
@ConditionalOnMissingBean
EmbeddedJMS
artemisServer
(
org
.
apache
.
activemq
.
artemis
.
core
.
config
.
Configuration
configuration
,
EmbeddedActiveMQ
embeddedActiveMq
(
org
.
apache
.
activemq
.
artemis
.
core
.
config
.
Configuration
configuration
,
JMSConfiguration
jmsConfiguration
,
JMSConfiguration
jmsConfiguration
,
ObjectProvider
<
ArtemisConfigurationCustomizer
>
configurationCustomizers
)
ObjectProvider
<
ArtemisConfigurationCustomizer
>
configurationCustomizers
)
{
throws
Exception
{
EmbeddedJMS
server
=
new
EmbeddedJMS
();
for
(
JMSQueueConfiguration
queueConfiguration
:
jmsConfiguration
.
getQueueConfigurations
())
{
String
queueName
=
queueConfiguration
.
getName
();
configuration
.
addAddressConfiguration
(
new
CoreAddressConfiguration
().
setName
(
queueName
).
addRoutingType
(
RoutingType
.
ANYCAST
)
.
addQueueConfiguration
(
new
CoreQueueConfiguration
().
setAddress
(
queueName
).
setName
(
queueName
)
.
setFilterString
(
queueConfiguration
.
getSelector
())
.
setDurable
(
queueConfiguration
.
isDurable
()).
setRoutingType
(
RoutingType
.
ANYCAST
)));
}
for
(
TopicConfiguration
topicConfiguration
:
jmsConfiguration
.
getTopicConfigurations
())
{
configuration
.
addAddressConfiguration
(
new
CoreAddressConfiguration
().
setName
(
topicConfiguration
.
getName
())
.
addRoutingType
(
RoutingType
.
MULTICAST
));
}
configurationCustomizers
.
orderedStream
().
forEach
((
customizer
)
->
customizer
.
customize
(
configuration
));
configurationCustomizers
.
orderedStream
().
forEach
((
customizer
)
->
customizer
.
customize
(
configuration
));
server
.
setConfiguration
(
configuration
);
EmbeddedActiveMQ
embeddedActiveMq
=
new
EmbeddedActiveMQ
();
server
.
setJmsConfiguration
(
jmsConfiguration
);
embeddedActiveMq
.
setConfiguration
(
configuration
);
server
.
setRegistry
(
new
ArtemisNoOpBindingRegistry
());
return
embeddedActiveMq
;
return
server
;
}
}
@Bean
@Bean
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfigurationTests.java
View file @
42e0dc14
...
@@ -31,7 +31,9 @@ import org.apache.activemq.artemis.api.core.SimpleString;
...
@@ -31,7 +31,9 @@ import org.apache.activemq.artemis.api.core.SimpleString;
import
org.apache.activemq.artemis.api.core.TransportConfiguration
;
import
org.apache.activemq.artemis.api.core.TransportConfiguration
;
import
org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory
;
import
org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory
;
import
org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory
;
import
org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory
;
import
org.apache.activemq.artemis.core.server.ActiveMQServer
;
import
org.apache.activemq.artemis.core.server.BindingQueryResult
;
import
org.apache.activemq.artemis.core.server.BindingQueryResult
;
import
org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ
;
import
org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory
;
import
org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory
;
import
org.apache.activemq.artemis.jms.server.config.JMSConfiguration
;
import
org.apache.activemq.artemis.jms.server.config.JMSConfiguration
;
import
org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration
;
import
org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration
;
...
@@ -39,7 +41,6 @@ import org.apache.activemq.artemis.jms.server.config.TopicConfiguration;
...
@@ -39,7 +41,6 @@ import org.apache.activemq.artemis.jms.server.config.TopicConfiguration;
import
org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl
;
import
org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl
;
import
org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationImpl
;
import
org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationImpl
;
import
org.apache.activemq.artemis.jms.server.config.impl.TopicConfigurationImpl
;
import
org.apache.activemq.artemis.jms.server.config.impl.TopicConfigurationImpl
;
import
org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.messaginghub.pooled.jms.JmsPoolConnectionFactory
;
import
org.messaginghub.pooled.jms.JmsPoolConnectionFactory
;
...
@@ -151,7 +152,7 @@ class ArtemisAutoConfigurationTests {
...
@@ -151,7 +152,7 @@ class ArtemisAutoConfigurationTests {
.
withPropertyValues
(
"spring.artemis.mode:embedded"
).
run
((
context
)
->
{
.
withPropertyValues
(
"spring.artemis.mode:embedded"
).
run
((
context
)
->
{
ArtemisProperties
properties
=
context
.
getBean
(
ArtemisProperties
.
class
);
ArtemisProperties
properties
=
context
.
getBean
(
ArtemisProperties
.
class
);
assertThat
(
properties
.
getMode
()).
isEqualTo
(
ArtemisMode
.
EMBEDDED
);
assertThat
(
properties
.
getMode
()).
isEqualTo
(
ArtemisMode
.
EMBEDDED
);
assertThat
(
context
).
hasSingleBean
(
Embedded
JMS
.
class
);
assertThat
(
context
).
hasSingleBean
(
Embedded
ActiveMQ
.
class
);
org
.
apache
.
activemq
.
artemis
.
core
.
config
.
Configuration
configuration
=
context
org
.
apache
.
activemq
.
artemis
.
core
.
config
.
Configuration
configuration
=
context
.
getBean
(
org
.
apache
.
activemq
.
artemis
.
core
.
config
.
Configuration
.
class
);
.
getBean
(
org
.
apache
.
activemq
.
artemis
.
core
.
config
.
Configuration
.
class
);
assertThat
(
configuration
.
isPersistenceEnabled
()).
isFalse
();
assertThat
(
configuration
.
isPersistenceEnabled
()).
isFalse
();
...
@@ -164,7 +165,7 @@ class ArtemisAutoConfigurationTests {
...
@@ -164,7 +165,7 @@ class ArtemisAutoConfigurationTests {
void
embeddedConnectionFactoryByDefault
()
{
void
embeddedConnectionFactoryByDefault
()
{
// No mode is specified
// No mode is specified
this
.
contextRunner
.
withUserConfiguration
(
EmptyConfiguration
.
class
).
run
((
context
)
->
{
this
.
contextRunner
.
withUserConfiguration
(
EmptyConfiguration
.
class
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Embedded
JMS
.
class
);
assertThat
(
context
).
hasSingleBean
(
Embedded
ActiveMQ
.
class
);
org
.
apache
.
activemq
.
artemis
.
core
.
config
.
Configuration
configuration
=
context
org
.
apache
.
activemq
.
artemis
.
core
.
config
.
Configuration
configuration
=
context
.
getBean
(
org
.
apache
.
activemq
.
artemis
.
core
.
config
.
Configuration
.
class
);
.
getBean
(
org
.
apache
.
activemq
.
artemis
.
core
.
config
.
Configuration
.
class
);
assertThat
(
configuration
.
isPersistenceEnabled
()).
isFalse
();
assertThat
(
configuration
.
isPersistenceEnabled
()).
isFalse
();
...
@@ -178,7 +179,7 @@ class ArtemisAutoConfigurationTests {
...
@@ -178,7 +179,7 @@ class ArtemisAutoConfigurationTests {
// No mode is specified
// No mode is specified
this
.
contextRunner
.
withUserConfiguration
(
EmptyConfiguration
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
EmptyConfiguration
.
class
)
.
withPropertyValues
(
"spring.artemis.embedded.enabled:false"
).
run
((
context
)
->
{
.
withPropertyValues
(
"spring.artemis.embedded.enabled:false"
).
run
((
context
)
->
{
assertThat
(
context
).
doesNotHaveBean
(
EmbeddedJMS
.
class
);
assertThat
(
context
).
doesNotHaveBean
(
ActiveMQServer
.
class
);
assertNettyConnectionFactory
(
getActiveMQConnectionFactory
(
context
.
getBean
(
ConnectionFactory
.
class
)),
assertNettyConnectionFactory
(
getActiveMQConnectionFactory
(
context
.
getBean
(
ConnectionFactory
.
class
)),
"localhost"
,
61616
);
"localhost"
,
61616
);
});
});
...
@@ -190,7 +191,7 @@ class ArtemisAutoConfigurationTests {
...
@@ -190,7 +191,7 @@ class ArtemisAutoConfigurationTests {
this
.
contextRunner
.
withUserConfiguration
(
EmptyConfiguration
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
EmptyConfiguration
.
class
)
.
withPropertyValues
(
"spring.artemis.mode:embedded"
,
"spring.artemis.embedded.enabled:false"
)
.
withPropertyValues
(
"spring.artemis.mode:embedded"
,
"spring.artemis.embedded.enabled:false"
)
.
run
((
context
)
->
{
.
run
((
context
)
->
{
assertThat
(
context
.
getBeansOfType
(
EmbeddedJMS
.
class
)).
isEmpty
();
assertThat
(
context
.
getBeansOfType
(
ActiveMQServer
.
class
)).
isEmpty
();
assertInVmConnectionFactory
(
getActiveMQConnectionFactory
(
context
.
getBean
(
ConnectionFactory
.
class
)));
assertInVmConnectionFactory
(
getActiveMQConnectionFactory
(
context
.
getBean
(
ConnectionFactory
.
class
)));
});
});
}
}
...
@@ -379,10 +380,10 @@ class ArtemisAutoConfigurationTests {
...
@@ -379,10 +380,10 @@ class ArtemisAutoConfigurationTests {
private
static
final
class
DestinationChecker
{
private
static
final
class
DestinationChecker
{
private
final
EmbeddedJMS
embeddedJms
;
private
final
ActiveMQServer
server
;
private
DestinationChecker
(
ApplicationContext
applicationContext
)
{
private
DestinationChecker
(
ApplicationContext
applicationContext
)
{
this
.
embeddedJms
=
applicationContext
.
getBean
(
EmbeddedJMS
.
class
);
this
.
server
=
applicationContext
.
getBean
(
EmbeddedActiveMQ
.
class
).
getActiveMQServer
(
);
}
}
void
checkQueue
(
String
name
,
boolean
shouldExist
)
{
void
checkQueue
(
String
name
,
boolean
shouldExist
)
{
...
@@ -395,7 +396,7 @@ class ArtemisAutoConfigurationTests {
...
@@ -395,7 +396,7 @@ class ArtemisAutoConfigurationTests {
void
checkDestination
(
String
name
,
RoutingType
routingType
,
boolean
shouldExist
)
{
void
checkDestination
(
String
name
,
RoutingType
routingType
,
boolean
shouldExist
)
{
try
{
try
{
BindingQueryResult
result
=
this
.
embeddedJms
.
getActiveMQServer
()
.
bindingQuery
(
new
SimpleString
(
name
));
BindingQueryResult
result
=
this
.
server
.
bindingQuery
(
new
SimpleString
(
name
));
assertThat
(
result
.
isExists
()).
isEqualTo
(
shouldExist
);
assertThat
(
result
.
isExists
()).
isEqualTo
(
shouldExist
);
if
(
shouldExist
)
{
if
(
shouldExist
)
{
assertThat
(
result
.
getAddressInfo
().
getRoutingType
()).
isEqualTo
(
routingType
);
assertThat
(
result
.
getAddressInfo
().
getRoutingType
()).
isEqualTo
(
routingType
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment