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
338c8c4f
Commit
338c8c4f
authored
Dec 21, 2020
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Allow to configure ActiveMQ Artemis with a broker url"
See gh-24302
parent
99b43cb6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
39 deletions
+70
-39
ArtemisConnectionFactoryFactory.java
...onfigure/jms/artemis/ArtemisConnectionFactoryFactory.java
+22
-15
ArtemisProperties.java
...ork/boot/autoconfigure/jms/artemis/ArtemisProperties.java
+29
-20
additional-spring-configuration-metadata.json
...es/META-INF/additional-spring-configuration-metadata.json
+4
-0
ArtemisAutoConfigurationTests.java
...oconfigure/jms/artemis/ArtemisAutoConfigurationTests.java
+15
-4
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisConnectionFactoryFactory.java
View file @
338c8c4f
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -44,6 +44,8 @@ import org.springframework.util.StringUtils;
*/
class
ArtemisConnectionFactoryFactory
{
private
static
final
String
DEFAULT_BROKER_URL
=
"tcp://localhost:61616"
;
static
final
String
[]
EMBEDDED_JMS_CLASSES
=
{
"org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS"
,
"org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ"
};
...
...
@@ -128,27 +130,32 @@ class ArtemisConnectionFactoryFactory {
private
<
T
extends
ActiveMQConnectionFactory
>
T
createNativeConnectionFactory
(
Class
<
T
>
factoryClass
)
throws
Exception
{
T
connectionFactory
;
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
String
url
=
this
.
properties
.
getBrokerUrl
();
if
(
StringUtils
.
hasText
(
url
))
{
Constructor
<
T
>
constructor
=
factoryClass
.
getConstructor
(
String
.
class
);
connectionFactory
=
constructor
.
newInstance
(
url
);
T
connectionFactory
=
newNativeConnectionFactory
(
factoryClass
);
String
user
=
this
.
properties
.
getUser
();
if
(
StringUtils
.
hasText
(
user
))
{
connectionFactory
.
setUser
(
user
);
connectionFactory
.
setPassword
(
this
.
properties
.
getPassword
());
}
else
{
return
connectionFactory
;
}
@SuppressWarnings
(
"deprecation"
)
private
<
T
extends
ActiveMQConnectionFactory
>
T
newNativeConnectionFactory
(
Class
<
T
>
factoryClass
)
throws
Exception
{
// Fallback if the broker url is not set
if
(!
StringUtils
.
hasText
(
this
.
properties
.
getBrokerUrl
())
&&
StringUtils
.
hasText
(
this
.
properties
.
getHost
()))
{
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
TransportConstants
.
HOST_PROP_NAME
,
this
.
properties
.
getHost
());
params
.
put
(
TransportConstants
.
PORT_PROP_NAME
,
this
.
properties
.
getPort
());
TransportConfiguration
transportConfiguration
=
new
TransportConfiguration
(
NettyConnectorFactory
.
class
.
getName
(),
params
);
Constructor
<
T
>
constructor
=
factoryClass
.
getConstructor
(
boolean
.
class
,
TransportConfiguration
[].
class
);
connectionFactory
=
constructor
.
newInstance
(
false
,
new
TransportConfiguration
[]
{
transportConfiguration
});
return
constructor
.
newInstance
(
false
,
new
TransportConfiguration
[]
{
transportConfiguration
});
}
String
user
=
this
.
properties
.
getUser
();
if
(
StringUtils
.
hasText
(
user
))
{
connectionFactory
.
setUser
(
user
);
connectionFactory
.
setPassword
(
this
.
properties
.
getPassword
());
}
return
connectionFactory
;
String
brokerUrl
=
StringUtils
.
hasText
(
this
.
properties
.
getBrokerUrl
())
?
this
.
properties
.
getBrokerUrl
()
:
DEFAULT_BROKER_URL
;
Constructor
<
T
>
constructor
=
factoryClass
.
getConstructor
(
String
.
class
);
return
constructor
.
newInstance
(
brokerUrl
);
}
}
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisProperties.java
View file @
338c8c4f
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -25,6 +25,7 @@ import org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants;
import
org.springframework.boot.autoconfigure.jms.JmsPoolConnectionFactoryProperties
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.DeprecatedConfigurationProperty
;
import
org.springframework.boot.context.properties.NestedConfigurationProperty
;
/**
...
...
@@ -44,25 +45,19 @@ public class ArtemisProperties {
private
ArtemisMode
mode
;
/**
* Artemis broker host.
*
* This property is deprecated. Use <code>brokerUrl</code> instead.
* Artemis broker port.
*/
@Deprecated
private
String
host
=
"localhost"
;
private
String
brokerUrl
;
/**
* Artemis broker port.
*
* This property is deprecated. Use <code>brokerUrl</code> instead.
* Artemis broker host.
*/
@Deprecated
private
int
port
=
61616
;
private
String
host
;
/**
* Artemis broker port.
*/
private
String
brokerUrl
=
"tcp://localhost:61616"
;
private
int
port
=
61616
;
/**
* Login user of the broker.
...
...
@@ -87,30 +82,44 @@ public class ArtemisProperties {
this
.
mode
=
mode
;
}
public
String
getBrokerUrl
()
{
return
this
.
brokerUrl
;
}
public
void
setBrokerUrl
(
String
brokerUrl
)
{
this
.
brokerUrl
=
brokerUrl
;
}
/**
* Return the host of the broker.
* @return the host
*/
@Deprecated
@DeprecatedConfigurationProperty
(
replacement
=
"spring.artemis.broker-url"
)
public
String
getHost
()
{
return
this
.
host
;
}
@Deprecated
public
void
setHost
(
String
host
)
{
this
.
host
=
host
;
}
/**
* Return the port of the broker.
* @return the port
*/
@Deprecated
@DeprecatedConfigurationProperty
(
replacement
=
"spring.artemis.broker-url"
)
public
int
getPort
()
{
return
this
.
port
;
}
@Deprecated
public
void
setPort
(
int
port
)
{
this
.
port
=
port
;
}
public
String
getBrokerUrl
()
{
return
this
.
brokerUrl
;
}
public
void
setBrokerUrl
(
String
brokerUrl
)
{
this
.
brokerUrl
=
brokerUrl
;
}
public
String
getUser
()
{
return
this
.
user
;
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
View file @
338c8c4f
...
...
@@ -352,6 +352,10 @@
"description"
:
"JMX name of the application admin MBean."
,
"defaultValue"
:
"org.springframework.boot:type=Admin,name=SpringApplication"
},
{
"name"
:
"spring.artemis.broker-url"
,
"defaultValue"
:
"tcp://localhost:61616"
},
{
"name"
:
"spring.artemis.pool.maximum-active-session-per-connection"
,
"deprecation"
:
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfigurationTests.java
View file @
338c8c4f
...
...
@@ -124,20 +124,31 @@ class ArtemisAutoConfigurationTests {
}
@Test
void
nativeConnectionFactoryCustomBrokerUrl
()
{
this
.
contextRunner
.
withUserConfiguration
(
EmptyConfiguration
.
class
)
.
withPropertyValues
(
"spring.artemis.mode:native"
,
"spring.artemis.broker-url:tcp://192.168.1.144:9876"
)
.
run
((
context
)
->
assertNettyConnectionFactory
(
getActiveMQConnectionFactory
(
getConnectionFactory
(
context
)),
"192.168.1.144"
,
9876
));
}
@Test
@Deprecated
void
nativeConnectionFactoryCustomHost
()
{
this
.
contextRunner
.
withUserConfiguration
(
EmptyConfiguration
.
class
)
.
withPropertyValues
(
"spring.artemis.mode:native"
,
"spring.artemis.host:192.168.1.144"
,
"spring.artemis.port:9876"
,
"spring.artemis.broker-url: "
)
"spring.artemis.port:9876"
)
.
run
((
context
)
->
assertNettyConnectionFactory
(
getActiveMQConnectionFactory
(
getConnectionFactory
(
context
)),
"192.168.1.144"
,
9876
));
}
@Test
void
nativeConnectionFactoryCustomUrl
()
{
@Deprecated
void
nativeConnectionFactoryCustomBrokerUrlAndHost
()
{
this
.
contextRunner
.
withUserConfiguration
(
EmptyConfiguration
.
class
)
.
withPropertyValues
(
"spring.artemis.mode:native"
,
"spring.artemis.broker-url:tcp://192.168.1.144:9876"
)
.
withPropertyValues
(
"spring.artemis.mode:native"
,
"spring.artemis.host:192.168.1.144"
,
"spring.artemis.port:9876"
,
"spring.artemis.broker-url=tcp://192.168.1.221:6543"
)
.
run
((
context
)
->
assertNettyConnectionFactory
(
getActiveMQConnectionFactory
(
getConnectionFactory
(
context
)),
"192.168.1.
144"
,
9876
));
getActiveMQConnectionFactory
(
getConnectionFactory
(
context
)),
"192.168.1.
221"
,
6543
));
}
@Test
...
...
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