Java Code Examples for org.apache.activemq.artemis.api.jms.ActiveMQJMSClient#createConnectionFactoryWithHA()
The following examples show how to use
org.apache.activemq.artemis.api.jms.ActiveMQJMSClient#createConnectionFactoryWithHA() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectionFactoryProvider.java From activemq-artemis with Apache License 2.0 | 6 votes |
private ActiveMQConnectionFactory createConnectionFactory() throws Exception { Map<String, Object> params = new HashMap<>(); params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "1"); final ActiveMQConnectionFactory activeMQConnectionFactory; if (configuration.getUrl() != null) { activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactory(configuration.getUrl(), null); } else { if (configuration.getHost() != null) { params.put(TransportConstants.HOST_PROP_NAME, configuration.getHost()); params.put(TransportConstants.PORT_PROP_NAME, configuration.getPort()); } if (configuration.isHa()) { activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params)); } else { activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params)); } } if (configuration.hasAuthentication()) { activeMQConnectionFactory.setUser(configuration.getUsername()); activeMQConnectionFactory.setPassword(configuration.getPassword()); } // The CF will probably be GCed since it was injected, so we disable the finalize check return activeMQConnectionFactory.disableFinalizeChecks(); }
Example 2
Source File: TCPSchema.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override protected ActiveMQConnectionFactory internalNewObject(URI uri, Map<String, String> query, String name) throws Exception { JMSConnectionOptions options = newConectionOptions(uri, query); List<TransportConfiguration> configurations = TCPTransportConfigurationSchema.getTransportConfigurations(uri, query, TransportConstants.ALLOWABLE_CONNECTOR_KEYS, name, NettyConnectorFactory.class.getName()); TransportConfiguration[] tcs = new TransportConfiguration[configurations.size()]; configurations.toArray(tcs); ActiveMQConnectionFactory factory; if (options.isHa()) { factory = ActiveMQJMSClient.createConnectionFactoryWithHA(options.getFactoryTypeEnum(), tcs); } else { factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(options.getFactoryTypeEnum(), tcs); } setData(uri, query, factory); checkIgnoredQueryFields(factory, query); return factory; }
Example 3
Source File: JGroupsSchema.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public ActiveMQConnectionFactory internalNewObject(URI uri, Map<String, String> query, String name) throws Exception { JMSConnectionOptions options = newConectionOptions(uri, query); DiscoveryGroupConfiguration dcConfig = JGroupsServerLocatorSchema.getDiscoveryGroupConfiguration(uri, query, name); ActiveMQConnectionFactory factory; if (options.isHa()) { factory = ActiveMQJMSClient.createConnectionFactoryWithHA(dcConfig, options.getFactoryTypeEnum()); } else { factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(dcConfig, options.getFactoryTypeEnum()); } return setData(uri, query, factory); }
Example 4
Source File: UDPSchema.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public ActiveMQConnectionFactory internalNewObject(URI uri, Map<String, String> query, String name) throws Exception { JMSConnectionOptions options = newConectionOptions(uri, query); DiscoveryGroupConfiguration dgc = UDPServerLocatorSchema.getDiscoveryGroupConfiguration(uri, query, getHost(uri), getPort(uri), name); ActiveMQConnectionFactory factory; if (options.isHa()) { factory = ActiveMQJMSClient.createConnectionFactoryWithHA(dgc, options.getFactoryTypeEnum()); } else { factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(dgc, options.getFactoryTypeEnum()); } return setData(uri, query, factory); }
Example 5
Source File: ConnectionFactoryURITest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testTCPURI() throws Exception { TransportConfiguration tc = new TransportConfiguration(NettyConnectorFactory.class.getName()); HashMap<String, Object> params = new HashMap<>(); params.put("host", "localhost1"); params.put("port", 61617); TransportConfiguration tc2 = new TransportConfiguration(NettyConnectorFactory.class.getName(), params); HashMap<String, Object> params2 = new HashMap<>(); params2.put("host", "localhost2"); params2.put("port", 61618); TransportConfiguration tc3 = new TransportConfiguration(NettyConnectorFactory.class.getName(), params2); ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, tc, tc2, tc3); URI tcp = parser.createSchema("tcp", connectionFactoryWithHA); ActiveMQConnectionFactory factory = parser.newObject(tcp, null); BeanUtilsBean bean = new BeanUtilsBean(); checkEquals(bean, connectionFactoryWithHA, factory); }
Example 6
Source File: ConnectionFactoryURITest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testJGroupsFileURI() throws Exception { DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration(); JGroupsFileBroadcastEndpointFactory endpointFactory = new JGroupsFileBroadcastEndpointFactory().setChannelName("channel-name").setFile("channel-file.xml"); discoveryGroupConfiguration.setName("foo").setRefreshTimeout(12345).setDiscoveryInitialWaitTimeout(5678).setBroadcastEndpointFactory(endpointFactory); ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF); URI tcp = parser.createSchema("jgroups", connectionFactoryWithHA); ActiveMQConnectionFactory factory = parser.newObject(tcp, null); DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration(); Assert.assertNotNull(dgc); BroadcastEndpointFactory befc = dgc.getBroadcastEndpointFactory(); Assert.assertNotNull(befc); Assert.assertTrue(befc instanceof JGroupsFileBroadcastEndpointFactory); Assert.assertEquals(dgc.getName(), "foo"); Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5678); Assert.assertEquals(dgc.getRefreshTimeout(), 12345); JGroupsFileBroadcastEndpointFactory fileBroadcastEndpointFactory = (JGroupsFileBroadcastEndpointFactory) befc; Assert.assertEquals(fileBroadcastEndpointFactory.getFile(), "channel-file.xml"); Assert.assertEquals(fileBroadcastEndpointFactory.getChannelName(), "channel-name"); BeanUtilsBean bean = new BeanUtilsBean(); checkEquals(bean, connectionFactoryWithHA, factory); }
Example 7
Source File: ConnectionFactoryURITest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testJGroupsPropertiesURI() throws Exception { DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration(); JGroupsPropertiesBroadcastEndpointFactory endpointFactory = new JGroupsPropertiesBroadcastEndpointFactory().setChannelName("channel-name").setProperties("param=val,param2-val2"); discoveryGroupConfiguration.setName("foo").setRefreshTimeout(12345).setDiscoveryInitialWaitTimeout(5678).setBroadcastEndpointFactory(endpointFactory); ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF); URI tcp = parser.createSchema("jgroups", connectionFactoryWithHA); ActiveMQConnectionFactory factory = parser.newObject(tcp, null); DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration(); Assert.assertNotNull(dgc); BroadcastEndpointFactory broadcastEndpointFactory = dgc.getBroadcastEndpointFactory(); Assert.assertNotNull(broadcastEndpointFactory); Assert.assertTrue(broadcastEndpointFactory instanceof JGroupsPropertiesBroadcastEndpointFactory); Assert.assertEquals(dgc.getName(), "foo"); Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5678); Assert.assertEquals(dgc.getRefreshTimeout(), 12345); JGroupsPropertiesBroadcastEndpointFactory propertiesBroadcastEndpointFactory = (JGroupsPropertiesBroadcastEndpointFactory) broadcastEndpointFactory; Assert.assertEquals(propertiesBroadcastEndpointFactory.getProperties(), "param=val,param2-val2"); Assert.assertEquals(propertiesBroadcastEndpointFactory.getChannelName(), "channel-name"); BeanUtilsBean bean = new BeanUtilsBean(); checkEquals(bean, connectionFactoryWithHA, factory); }
Example 8
Source File: JMSFailoverTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testCreateQueue() throws Exception { liveJMSServer.createQueue(true, "queue1", null, true, "/queue/queue1"); assertNotNull(ctx1.lookup("/queue/queue1")); ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc); jbcf.setReconnectAttempts(-1); Connection conn = null; try { conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession(); JMSUtil.crash(liveServer, coreSession); assertNotNull(ctx2.lookup("/queue/queue1")); } finally { if (conn != null) { conn.close(); } } }
Example 9
Source File: JMSFailoverTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testCreateTopic() throws Exception { liveJMSServer.createTopic(true, "topic", "/topic/t1"); assertNotNull(ctx1.lookup("//topic/t1")); ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc); jbcf.setReconnectAttempts(-1); Connection conn = null; try { conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession(); JMSUtil.crash(liveServer, coreSession); assertNotNull(ctx2.lookup("/topic/t1")); } finally { if (conn != null) { conn.close(); } } }
Example 10
Source File: ClusteredBridgeTestBase.java From activemq-artemis with Apache License 2.0 | 5 votes |
public ConnectionFactoryFactory getConnectionFactoryFactory() { ConnectionFactoryFactory cff = new ConnectionFactoryFactory() { @Override public ConnectionFactory createConnectionFactory() throws Exception { ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.XA_CF, liveConnector); cf.getServerLocator().setReconnectAttempts(15); return cf; } }; return cff; }
Example 11
Source File: ConnectionFactoryURITest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testUDPURI() throws Exception { DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration(); UDPBroadcastEndpointFactory endpoint = new UDPBroadcastEndpointFactory(); endpoint.setGroupPort(3333).setGroupAddress("wahey").setLocalBindPort(555).setLocalBindAddress("uhuh"); discoveryGroupConfiguration.setName("foo").setRefreshTimeout(12345).setDiscoveryInitialWaitTimeout(5678).setBroadcastEndpointFactory(endpoint); ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF); URI tcp = parser.createSchema("udp", connectionFactoryWithHA); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(tcp.toString()); DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration(); Assert.assertNotNull(dgc); BroadcastEndpointFactory befc = dgc.getBroadcastEndpointFactory(); Assert.assertNotNull(befc); Assert.assertTrue(befc instanceof UDPBroadcastEndpointFactory); UDPBroadcastEndpointFactory ubgc = (UDPBroadcastEndpointFactory) befc; Assert.assertEquals("wahey", ubgc.getGroupAddress()); Assert.assertEquals(3333, ubgc.getGroupPort()); //these 2 are transient // These will take the System.properties used on the testsuite, // for that reason we take them as != instead of checking for null Assert.assertNotEquals("uhuh", ubgc.getLocalBindAddress()); Assert.assertNotEquals(555, ubgc.getLocalBindPort()); Assert.assertEquals("foo", dgc.getName()); Assert.assertEquals(5678, dgc.getDiscoveryInitialWaitTimeout()); Assert.assertEquals(12345, dgc.getRefreshTimeout()); BeanUtilsBean bean = new BeanUtilsBean(); checkEquals(bean, connectionFactoryWithHA, factory); }
Example 12
Source File: JMSServerManagerImpl.java From activemq-artemis with Apache License 2.0 | 4 votes |
/** * @param cfConfig * @return * @throws ActiveMQException */ protected ActiveMQConnectionFactory internalCreateCFPOJO(final ConnectionFactoryConfiguration cfConfig) throws ActiveMQException { ActiveMQConnectionFactory cf; if (cfConfig.getDiscoveryGroupName() != null) { DiscoveryGroupConfiguration groupConfig = server.getConfiguration().getDiscoveryGroupConfigurations().get(cfConfig.getDiscoveryGroupName()); if (groupConfig == null) { throw ActiveMQJMSServerBundle.BUNDLE.discoveryGroupDoesntExist(cfConfig.getDiscoveryGroupName()); } if (cfConfig.isHA()) { cf = ActiveMQJMSClient.createConnectionFactoryWithHA(groupConfig, cfConfig.getFactoryType()); } else { cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(groupConfig, cfConfig.getFactoryType()); } } else { if (cfConfig.getConnectorNames() == null || cfConfig.getConnectorNames().size() == 0) { throw ActiveMQJMSServerBundle.BUNDLE.noConnectorNameOnCF(); } TransportConfiguration[] configs = new TransportConfiguration[cfConfig.getConnectorNames().size()]; int count = 0; for (String name : cfConfig.getConnectorNames()) { TransportConfiguration connector = server.getConfiguration().getConnectorConfigurations().get(name); if (connector == null) { throw ActiveMQJMSServerBundle.BUNDLE.noConnectorNameConfiguredOnCF(name); } correctInvalidNettyConnectorHost(connector); configs[count++] = connector; } if (cfConfig.isHA()) { cf = ActiveMQJMSClient.createConnectionFactoryWithHA(cfConfig.getFactoryType(), configs); } else { cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(cfConfig.getFactoryType(), configs); } } cf.setClientID(cfConfig.getClientID()); cf.setClientFailureCheckPeriod(cfConfig.getClientFailureCheckPeriod()); cf.setConnectionTTL(cfConfig.getConnectionTTL()); cf.setCallTimeout(cfConfig.getCallTimeout()); cf.setCallFailoverTimeout(cfConfig.getCallFailoverTimeout()); cf.setCacheLargeMessagesClient(cfConfig.isCacheLargeMessagesClient()); cf.setMinLargeMessageSize(cfConfig.getMinLargeMessageSize()); cf.setConsumerWindowSize(cfConfig.getConsumerWindowSize()); cf.setConsumerMaxRate(cfConfig.getConsumerMaxRate()); cf.setConfirmationWindowSize(cfConfig.getConfirmationWindowSize()); cf.setProducerWindowSize(cfConfig.getProducerWindowSize()); cf.setProducerMaxRate(cfConfig.getProducerMaxRate()); cf.setBlockOnAcknowledge(cfConfig.isBlockOnAcknowledge()); cf.setBlockOnDurableSend(cfConfig.isBlockOnDurableSend()); cf.setBlockOnNonDurableSend(cfConfig.isBlockOnNonDurableSend()); cf.setAutoGroup(cfConfig.isAutoGroup()); cf.setPreAcknowledge(cfConfig.isPreAcknowledge()); cf.setConnectionLoadBalancingPolicyClassName(cfConfig.getLoadBalancingPolicyClassName()); cf.setTransactionBatchSize(cfConfig.getTransactionBatchSize()); cf.setDupsOKBatchSize(cfConfig.getDupsOKBatchSize()); cf.setUseGlobalPools(cfConfig.isUseGlobalPools()); cf.setScheduledThreadPoolMaxSize(cfConfig.getScheduledThreadPoolMaxSize()); cf.setThreadPoolMaxSize(cfConfig.getThreadPoolMaxSize()); cf.setRetryInterval(cfConfig.getRetryInterval()); cf.setRetryIntervalMultiplier(cfConfig.getRetryIntervalMultiplier()); cf.setMaxRetryInterval(cfConfig.getMaxRetryInterval()); cf.setReconnectAttempts(cfConfig.getReconnectAttempts()); cf.setFailoverOnInitialConnection(cfConfig.isFailoverOnInitialConnection()); cf.setCompressLargeMessage(cfConfig.isCompressLargeMessages()); cf.setGroupID(cfConfig.getGroupID()); cf.setProtocolManagerFactoryStr(cfConfig.getProtocolManagerFactoryStr()); cf.setDeserializationBlackList(cfConfig.getDeserializationBlackList()); cf.setDeserializationWhiteList(cfConfig.getDeserializationWhiteList()); cf.setInitialMessagePacketSize(cfConfig.getInitialMessagePacketSize()); cf.setEnable1xPrefixes(cfConfig.isEnable1xPrefixes()); cf.setEnableSharedClientID(cfConfig.isEnableSharedClientID()); cf.setUseTopologyForLoadBalancing(cfConfig.getUseTopologyForLoadBalancing()); return cf; }
Example 13
Source File: LargeMessageOverBridgeTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
/** * The message won't be large to the client while it will be considered large through the bridge * * @throws Exception */ @Test public void testSendLargeForBridge() throws Exception { createQueue(QUEUE); Queue queue = (Queue) context1.lookup("queue/" + QUEUE); ActiveMQConnectionFactory cf1 = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, generateInVMParams(1))); cf1.setMinLargeMessageSize(200 * 1024); Connection conn1 = cf1.createConnection(); Session session1 = conn1.createSession(true, Session.SESSION_TRANSACTED); MessageProducer prod1 = session1.createProducer(queue); Connection conn2 = cf2.createConnection(); Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons2 = session2.createConsumer(queue); conn2.start(); byte[] bytes = new byte[150 * 1024]; for (int i = 0; i < bytes.length; i++) { bytes[i] = getSamplebyte(i); } for (int i = 0; i < 10; i++) { BytesMessage msg = session1.createBytesMessage(); msg.writeBytes(bytes); prod1.send(msg); } session1.commit(); for (int i = 0; i < 5; i++) { BytesMessage msg2 = (BytesMessage) cons2.receive(5000); assertNotNull(msg2); msg2.acknowledge(); for (int j = 0; j < bytes.length; j++) { assertEquals("Position " + i, msg2.readByte(), bytes[j]); } } conn1.close(); conn2.close(); }
Example 14
Source File: JMSBridgeReconnectionTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
private void performCrashAndReconnect(boolean restart) throws Exception { cff1xa = new ConnectionFactoryFactory() { @Override public Object createConnectionFactory() throws Exception { ActiveMQXAConnectionFactory cf = (ActiveMQXAConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.XA_CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, params1)); // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection cf.setReconnectAttempts(-1); cf.setBlockOnNonDurableSend(true); cf.setBlockOnDurableSend(true); cf.setCacheLargeMessagesClient(true); return cf; } }; DummyTransactionManager tm = new DummyTransactionManager(); DummyTransaction tx = new DummyTransaction(); tm.tx = tx; JMSBridgeImpl bridge = new JMSBridgeImpl(cff0xa, cff1xa, sourceQueueFactory, targetQueueFactory, null, null, null, null, null, 1000, -1, QualityOfServiceMode.ONCE_AND_ONLY_ONCE, 10, 5000, null, null, false).setBridgeName("test-bridge"); addActiveMQComponent(bridge); bridge.setTransactionManager(tm); bridge.start(); // Now crash the dest server instanceLog.debug("About to crash server"); server1.stop(); if (restart) { server1.start(); } // Wait a while before starting up to simulate the dest being down for a while instanceLog.debug("Waiting 5 secs before bringing server back up"); Thread.sleep(TIME_WAIT); instanceLog.debug("Done wait"); bridge.stop(); if (restart) { assertTrue(tx.rolledback); assertTrue(tx.targetConnected); } else { assertTrue(tx.rolledback); assertFalse(tx.targetConnected); } }
Example 15
Source File: ConnectionFactoryURITest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testWeirdEncodingsOnIP() throws Exception { // This is to make things worse. Having & and = on the property shouldn't break it final String BROKEN_PROPERTY = "e80::56ee:75ff:fe53:e6a7%25enp0s25&host=[fe80::56ee:75ff:fe53:e6a7]#"; Map<String, Object> params = new HashMap<>(); params.put(TransportConstants.LOCAL_ADDRESS_PROP_NAME, BROKEN_PROPERTY); TransportConfiguration configuration = new TransportConfiguration(NettyConnector.class.getName(), params); ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, configuration); URI uri = factory.toURI(); ActiveMQConnectionFactory newFactory = ActiveMQJMSClient.createConnectionFactory(uri.toString(), "somefactory"); TransportConfiguration[] initialConnectors = ((ServerLocatorImpl) newFactory.getServerLocator()).getInitialConnectors(); Assert.assertEquals(1, initialConnectors.length); Assert.assertEquals(BROKEN_PROPERTY, initialConnectors[0].getParams().get(TransportConstants.LOCAL_ADDRESS_PROP_NAME).toString()); }