use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project activemq-artemis by apache.
the class ConnectionFactorySerializationTest method createDiscoveryFactoryUDP.
private void createDiscoveryFactoryUDP() throws Exception {
// Deploy a connection factory with discovery
List<String> bindings = new ArrayList<>();
bindings.add("MyConnectionFactory");
final String groupAddress = getUDPDiscoveryAddress();
final int port = getUDPDiscoveryPort();
String localBindAddress = getLocalHost().getHostAddress();
UDPBroadcastEndpointFactory config = new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress).setGroupPort(port).setLocalBindAddress(localBindAddress).setLocalBindPort(8580);
DiscoveryGroupConfiguration dcConfig = new DiscoveryGroupConfiguration().setName("dg1").setRefreshTimeout(5000).setDiscoveryInitialWaitTimeout(5000).setBroadcastEndpointFactory(config);
jmsServer.getActiveMQServer().getConfiguration().getDiscoveryGroupConfigurations().put(dcConfig.getName(), dcConfig);
jmsServer.createConnectionFactory("MyConnectionFactory", false, JMSFactoryType.CF, dcConfig.getName(), "/MyConnectionFactory");
}
use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project activemq-artemis by apache.
the class ConnectionFactoryWithJGroupsSerializationTest method setUp.
@Override
@Before
public void setUp() throws Exception {
try {
super.setUp();
PlainConfigurator configurator = new PlainConfigurator(jgroupsConfigString);
channel = new JChannel(configurator);
String channelName1 = "channel1";
String channelName2 = "channel2";
BroadcastEndpointFactory jgroupsBroadcastCfg1 = new ChannelBroadcastEndpointFactory(channel, channelName1);
BroadcastEndpointFactory jgroupsBroadcastCfg2 = new JGroupsFileBroadcastEndpointFactory().setChannelName(channelName2).setFile(jgroupsConfigString);
DiscoveryGroupConfiguration dcConfig1 = new DiscoveryGroupConfiguration().setName("dg1").setRefreshTimeout(5000).setDiscoveryInitialWaitTimeout(5000).setBroadcastEndpointFactory(jgroupsBroadcastCfg1);
DiscoveryGroupConfiguration dcConfig2 = new DiscoveryGroupConfiguration().setName("dg2").setRefreshTimeout(5000).setDiscoveryInitialWaitTimeout(5000).setBroadcastEndpointFactory(jgroupsBroadcastCfg2);
jmsServer.getActiveMQServer().getConfiguration().getDiscoveryGroupConfigurations().put(dcConfig1.getName(), dcConfig1);
jmsServer.getActiveMQServer().getConfiguration().getDiscoveryGroupConfigurations().put(dcConfig2.getName(), dcConfig2);
jmsServer.createConnectionFactory("ConnectionFactory1", false, JMSFactoryType.CF, dcConfig1.getName(), "/ConnectionFactory1");
jmsServer.createConnectionFactory("ConnectionFactory2", false, JMSFactoryType.CF, dcConfig2.getName(), "/ConnectionFactory2");
testQueue = createQueue("testQueueFor1389");
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project activemq-artemis by apache.
the class SimpleJNDIClientTest method testRemoteCFWithJgroupsWithTransportConfigFile.
@Test
public void testRemoteCFWithJgroupsWithTransportConfigFile() throws Exception {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory.class.getCanonicalName());
props.put("connectionFactory.myConnectionFactory", "jgroups://testChannelName?file=test-jgroups-file_ping.xml&" + ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" + ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000");
Context ctx = new InitialContext(props);
ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration();
Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout());
Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout());
BroadcastEndpoint broadcastEndpoint = cf.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory().createBroadcastEndpoint();
Assert.assertTrue(broadcastEndpoint instanceof JGroupsFileBroadcastEndpoint);
broadcastEndpoint.close(false);
}
use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project activemq-artemis by apache.
the class JMSServerDeployerTest method setUp.
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@Override
@Before
public void setUp() throws Exception {
super.setUp();
DiscoveryGroupConfiguration dcg = new DiscoveryGroupConfiguration().setName("mygroup").setRefreshTimeout(5432).setDiscoveryInitialWaitTimeout(5432).setBroadcastEndpointFactory(new UDPBroadcastEndpointFactory().setGroupAddress(getUDPDiscoveryAddress()).setGroupPort(getUDPDiscoveryPort()).setLocalBindAddress("172.16.8.10"));
config = createBasicConfig().addConnectorConfiguration("netty", new TransportConfiguration(NettyConnectorFactory.class.getName())).addDiscoveryGroupConfiguration("mygroup", dcg);
ActiveMQServer server = createServer(false, config);
jmsServer = new JMSServerManagerImpl(server);
context = new InVMNamingContext();
jmsServer.setRegistry(new JndiBindingRegistry(context));
jmsServer.start();
}
use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project wildfly by wildfly.
the class ActiveMQServerService method start.
@Override
public synchronized void start(final StartContext context) throws StartException {
ClassLoader origTCCL = org.wildfly.security.manager.WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
// Validate whether the AIO native layer can be used
JournalType jtype = configuration.getJournalType();
if (jtype == JournalType.ASYNCIO) {
boolean supportsAIO = AIOSequentialFileFactory.isSupported();
if (supportsAIO == false) {
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
if (osName.contains("nux")) {
ROOT_LOGGER.aioInfoLinux();
} else {
ROOT_LOGGER.aioInfo();
}
configuration.setJournalType(JournalType.NIO);
}
}
// Setup paths
configuration.setBindingsDirectory(pathConfig.resolveBindingsPath(pathManager.get()));
configuration.setLargeMessagesDirectory(pathConfig.resolveLargeMessagePath(pathManager.get()));
configuration.setJournalDirectory(pathConfig.resolveJournalPath(pathManager.get()));
configuration.setPagingDirectory(pathConfig.resolvePagingPath(pathManager.get()));
pathConfig.registerCallbacks(pathManager.get());
try {
// Update the acceptor/connector port/host values from the
// Map the socket bindings onto the connectors/acceptors
Collection<TransportConfiguration> acceptors = configuration.getAcceptorConfigurations();
Collection<TransportConfiguration> connectors = configuration.getConnectorConfigurations().values();
Collection<BroadcastGroupConfiguration> broadcastGroups = configuration.getBroadcastGroupConfigurations();
Map<String, DiscoveryGroupConfiguration> discoveryGroups = configuration.getDiscoveryGroupConfigurations();
TransportConfigOperationHandlers.processConnectorBindings(connectors, socketBindings, outboundSocketBindings);
if (acceptors != null) {
for (TransportConfiguration tc : acceptors) {
// If there is a socket binding set the HOST/PORT values
Object socketRef = tc.getParams().remove(SOCKET_REF);
if (socketRef != null) {
String name = socketRef.toString();
SocketBinding binding = socketBindings.get(name).get();
if (binding == null) {
throw MessagingLogger.ROOT_LOGGER.failedToFindConnectorSocketBinding(tc.getName());
}
binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
InetSocketAddress socketAddress = binding.getSocketAddress();
tc.getParams().put(HOST, socketAddress.getAddress().getHostAddress());
tc.getParams().put(PORT, socketAddress.getPort());
}
}
}
if (broadcastGroups != null) {
final List<BroadcastGroupConfiguration> newConfigs = new ArrayList<>();
for (final BroadcastGroupConfiguration config : broadcastGroups) {
final String name = config.getName();
final String key = "broadcast" + name;
if (commandDispatcherFactories.containsKey(key)) {
BroadcastCommandDispatcherFactory commandDispatcherFactory = commandDispatcherFactories.get(key).get();
String clusterName = clusterNames.get(key);
newConfigs.add(JGroupsBroadcastGroupAdd.createBroadcastGroupConfiguration(name, config, commandDispatcherFactory, clusterName));
} else {
final Supplier<SocketBinding> bindingSupplier = groupBindings.get(key);
if (bindingSupplier == null) {
throw MessagingLogger.ROOT_LOGGER.failedToFindBroadcastSocketBinding(name);
}
final SocketBinding binding = bindingSupplier.get();
binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
newConfigs.add(SocketBroadcastGroupAdd.createBroadcastGroupConfiguration(name, config, binding));
}
}
configuration.getBroadcastGroupConfigurations().clear();
configuration.getBroadcastGroupConfigurations().addAll(newConfigs);
}
if (discoveryGroups != null) {
configuration.setDiscoveryGroupConfigurations(new HashMap<>());
for (final Map.Entry<String, DiscoveryGroupConfiguration> entry : discoveryGroups.entrySet()) {
final String name = entry.getKey();
final String key = "discovery" + name;
final DiscoveryGroupConfiguration config;
if (commandDispatcherFactories.containsKey(key)) {
BroadcastCommandDispatcherFactory commandDispatcherFactory = commandDispatcherFactories.get(key).get();
String clusterName = clusterNames.get(key);
config = JGroupsDiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, entry.getValue(), commandDispatcherFactory, clusterName);
} else {
final Supplier<SocketBinding> binding = groupBindings.get(key);
if (binding == null) {
throw MessagingLogger.ROOT_LOGGER.failedToFindDiscoverySocketBinding(name);
}
config = SocketDiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, entry.getValue(), binding.get());
binding.get().getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding.get()));
}
configuration.getDiscoveryGroupConfigurations().put(name, config);
}
}
// security - if an Elytron domain has been defined we delegate security checks to the Elytron based security manager.
final ActiveMQSecurityManager securityManager;
if (configuration.isSecurityEnabled()) {
if (elytronSecurityDomain.isPresent()) {
securityManager = new ElytronSecurityManager(elytronSecurityDomain.get().get());
} else {
securityManager = new WildFlySecurityManager();
}
} else {
securityManager = null;
}
// insert possible credential source hold passwords
setBridgePasswordsFromCredentialSource();
setClusterPasswordFromCredentialSource();
if (dataSource.isPresent()) {
final DataSource ds = dataSource.get().get();
DatabaseStorageConfiguration dbConfiguration = (DatabaseStorageConfiguration) configuration.getStoreConfiguration();
dbConfiguration.setDataSource(ds);
// inject the datasource into the PropertySQLProviderFactory to be able to determine the
// type of database for the datasource metadata
PropertySQLProvider.Factory sqlProviderFactory = new PropertySQLProvider.Factory(ds);
dbConfiguration.setSqlProvider(sqlProviderFactory);
configuration.setStoreConfiguration(dbConfiguration);
ROOT_LOGGER.infof("use JDBC store for Artemis server, bindingsTable:%s", dbConfiguration.getBindingsTableName());
}
final MBeanServer mbs = mbeanServer.isPresent() ? mbeanServer.get().get() : null;
// Now start the server
server = new ActiveMQServerImpl(configuration, mbs, securityManager);
if (ServerDefinition.CLUSTER_PASSWORD.getDefaultValue().asString().equals(server.getConfiguration().getClusterPassword())) {
server.getConfiguration().setClusterPassword(java.util.UUID.randomUUID().toString());
}
for (Interceptor incomingInterceptor : incomingInterceptors) {
server.getServiceRegistry().addIncomingInterceptor(incomingInterceptor);
}
for (Interceptor outgoingInterceptor : outgoingInterceptors) {
server.getServiceRegistry().addOutgoingInterceptor(outgoingInterceptor);
}
// the server is actually started by the Jakarta Messaging Service.
} catch (Exception e) {
throw MessagingLogger.ROOT_LOGGER.failedToStartService(e);
} finally {
org.wildfly.security.manager.WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(origTCCL);
}
}
Aggregations