Adding an optional method of providing connection
details Change-Id: I8d3dc077885e764d192a8195165777b04bf2f85e
This commit is contained in:
parent
d4a27f5321
commit
569aa6a9a1
@ -4,6 +4,8 @@ import eu.nebulouscloud.exn.core.Context
|
||||
import eu.nebulouscloud.exn.core.Publisher
|
||||
import eu.nebulouscloud.exn.core.StatePublisher
|
||||
import eu.nebulouscloud.exn.handlers.ConnectorHandler
|
||||
import eu.nebulouscloud.exn.settings.ExnConfig
|
||||
import eu.nebulouscloud.exn.settings.StaticExnConfig
|
||||
import org.apache.qpid.protonj2.client.Message
|
||||
import org.apache.qpid.protonj2.client.exceptions.ClientException
|
||||
import org.slf4j.Logger
|
||||
@ -83,7 +85,9 @@ class MyConnectorHandler extends ConnectorHandler {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
||||
|
||||
Connector c = new Connector(
|
||||
|
||||
"ui",
|
||||
new MyConnectorHandler(),
|
||||
[
|
||||
@ -92,7 +96,13 @@ public static void main(String[] args) {
|
||||
],
|
||||
[],
|
||||
true,
|
||||
true
|
||||
true,
|
||||
new StaticExnConfig(
|
||||
'localhost',
|
||||
5672,
|
||||
"admin",
|
||||
"admin"
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
|
@ -3,6 +3,7 @@ import eu.nebulouscloud.exn.core.Consumer
|
||||
import eu.nebulouscloud.exn.core.Context
|
||||
import eu.nebulouscloud.exn.core.Handler
|
||||
import eu.nebulouscloud.exn.handlers.ConnectorHandler
|
||||
import eu.nebulouscloud.exn.settings.StaticExnConfig
|
||||
import org.apache.qpid.protonj2.client.Message
|
||||
import org.apache.qpid.protonj2.client.exceptions.ClientException
|
||||
import org.slf4j.Logger
|
||||
@ -43,7 +44,13 @@ public static void main(String[] args) {
|
||||
}
|
||||
}
|
||||
},true,true),
|
||||
]
|
||||
],
|
||||
new StaticExnConfig(
|
||||
'localhosts',
|
||||
5672,
|
||||
"admin",
|
||||
"admin"
|
||||
)
|
||||
)
|
||||
c.start()
|
||||
} catch (ClientException e) {
|
||||
|
@ -34,7 +34,8 @@ public class Connector {
|
||||
List<Publisher> publishers,
|
||||
List<Consumer> consumers,
|
||||
boolean enableState = true,
|
||||
boolean enableHealth = true
|
||||
boolean enableHealth = true,
|
||||
ExnConfig configuration
|
||||
) {
|
||||
|
||||
assert component
|
||||
@ -43,11 +44,16 @@ public class Connector {
|
||||
this.running = new AtomicBoolean(true);
|
||||
this.handler = new AtomicReference<>(handler)
|
||||
this.config = ConfigFactory.create(ExnConfig.class)
|
||||
ExnConfig config = ConfigFactory.create(ExnConfig.class)
|
||||
|
||||
if (configuration == null ){
|
||||
configuration = ConfigFactory.create(ExnConfig.class)
|
||||
}
|
||||
|
||||
this.config = configuration
|
||||
this.context = new AtomicReference<>(
|
||||
new Context(
|
||||
"${config.url()}:${config.port()}",
|
||||
"${config.baseName()}.${this.component}"
|
||||
"${configuration .url()}:${configuration .port()}",
|
||||
"${configuration .baseName()}.${this.component}"
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -0,0 +1,71 @@
|
||||
package eu.nebulouscloud.exn.settings
|
||||
|
||||
import org.aeonbits.owner.Config
|
||||
import org.aeonbits.owner.Config.DefaultValue
|
||||
import org.aeonbits.owner.Config.Key
|
||||
import org.aeonbits.owner.Config.Sources
|
||||
|
||||
@Sources([
|
||||
"file:./exn.properties",
|
||||
"classpath:exn.properties",
|
||||
"system:properties",
|
||||
"system:env"
|
||||
])
|
||||
public class StaticExnConfig implements ExnConfig {
|
||||
|
||||
private final String baseName
|
||||
private final Integer port
|
||||
private final String url
|
||||
private final Integer healthTimeout
|
||||
private final String username
|
||||
private final String password
|
||||
|
||||
def StaticExnConfig(
|
||||
String url,
|
||||
Integer port,
|
||||
String username,
|
||||
String password,
|
||||
Integer healthTimeout=15,
|
||||
String baseName='eu.nebulous'
|
||||
){
|
||||
|
||||
this.url = url
|
||||
this.port = port
|
||||
this.username = username
|
||||
this.password = password
|
||||
this.baseName = baseName
|
||||
this.healthTimeout = healthTimeout
|
||||
|
||||
|
||||
}
|
||||
|
||||
public String baseName(){
|
||||
return this.baseName
|
||||
}
|
||||
|
||||
public Integer healthTimeout(){
|
||||
return this.healthTimeout
|
||||
|
||||
}
|
||||
|
||||
public String url(){
|
||||
return this.url
|
||||
|
||||
}
|
||||
|
||||
public int port(){
|
||||
return this.port
|
||||
|
||||
}
|
||||
|
||||
public String username(){
|
||||
return this.username
|
||||
}
|
||||
|
||||
public String password(){
|
||||
return this.password
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user