Java Code Examples for com.hazelcast.config.Config#setProperty()
The following examples show how to use
com.hazelcast.config.Config#setProperty() .
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: Cluster.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
public Member(Parallelism parallelism) { this.parallelism = parallelism; this.name = String.format("%s-member-%d", Cluster.this.name, nodeId); // configure the cluster Config cfg = new Config(); cfg.setClusterName(id); cfg.setInstanceName(name); cfg.getQueueConfig(TasksScatterName).setMaxSize(numMembers()*2); // disable Hazelcast's automatic phone home "feature", which is on by default cfg.setProperty("hazelcast.phone.home.enabled", "false"); inst = Hazelcast.newHazelcastInstance(cfg); log("node started on cluster %s", id); activeId = new Value<>(inst, TasksActiveIdName); scatter = inst.getQueue(TasksScatterName); gather = inst.getQueue(TasksGatherName); }
Example 2
Source File: CachingConfig.java From Spring-5.0-Cookbook with MIT License | 5 votes |
@Bean public Config hazelCastConfig() { Config config = new Config(); config.setInstanceName("hazelcast-packt-cache"); config.setProperty("hazelcast.jmx", "true"); MapConfig deptCache = new MapConfig(); deptCache.setTimeToLiveSeconds(20); deptCache.setEvictionPolicy(EvictionPolicy.LFU); config.getMapConfigs().put("hazeldept",deptCache); return config; }
Example 3
Source File: ServiceCacheConfiguration.java From iotplatform with Apache License 2.0 | 5 votes |
private void addZkConfig(Config config) { config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); config.setProperty(GroupProperty.DISCOVERY_SPI_ENABLED.getName(), Boolean.TRUE.toString()); DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig(new ZookeeperDiscoveryStrategyFactory()); discoveryStrategyConfig.addProperty(ZookeeperDiscoveryProperties.ZOOKEEPER_URL.key(), zkUrl); discoveryStrategyConfig.addProperty(ZookeeperDiscoveryProperties.ZOOKEEPER_PATH.key(), zkDir); discoveryStrategyConfig.addProperty(ZookeeperDiscoveryProperties.GROUP.key(), HAZELCAST_CLUSTER_NAME); config.getNetworkConfig().getJoin().getDiscoveryConfig().addDiscoveryStrategyConfig(discoveryStrategyConfig); }
Example 4
Source File: HazelcastTestFactory.java From ratelimitj with Apache License 2.0 | 5 votes |
static HazelcastInstance newStandaloneHazelcastInstance() { Config config = new Config(); config.setProperty("hazelcast.logging.type", "slf4j"); config.setProperty("hazelcast.shutdownhook.enabled", "false"); NetworkConfig network = config.getNetworkConfig(); network.getJoin().getTcpIpConfig().setEnabled(false); network.getJoin().getMulticastConfig().setEnabled(false); return Hazelcast.newHazelcastInstance(config); }
Example 5
Source File: ClusterNode.java From modernmt with Apache License 2.0 | 5 votes |
private Config getHazelcastConfig(NodeConfig nodeConfig, long interval, TimeUnit unit) { Config hazelcastConfig = new XmlConfigBuilder().build(); hazelcastConfig.setGroupConfig( new GroupConfig().setName(this.clusterName)); NetworkConfig networkConfig = nodeConfig.getNetworkConfig(); if (unit != null && interval > 0L) { long seconds = Math.max(unit.toSeconds(interval), 1L); hazelcastConfig.setProperty("hazelcast.max.join.seconds", Long.toString(seconds)); } String host = networkConfig.getHost(); if (host != null) hazelcastConfig.getNetworkConfig().setPublicAddress(host); hazelcastConfig.getNetworkConfig().setPort(networkConfig.getPort()); String listenInterface = networkConfig.getListeningInterface(); if (listenInterface != null) { hazelcastConfig.getNetworkConfig().getInterfaces() .setEnabled(true) .addInterface(listenInterface); hazelcastConfig.setProperty("hazelcast.local.localAddress", listenInterface); hazelcastConfig.setProperty("hazelcast.local.publicAddress", listenInterface); } JoinConfig joinConfig = networkConfig.getJoinConfig(); JoinConfig.Member[] members = joinConfig.getMembers(); if (members != null && members.length > 0) { TcpIpConfig tcpIpConfig = hazelcastConfig.getNetworkConfig().getJoin().getTcpIpConfig(); tcpIpConfig.setConnectionTimeoutSeconds(joinConfig.getTimeout()); tcpIpConfig.setEnabled(true); for (JoinConfig.Member member : members) tcpIpConfig.addMember(member.getHost() + ":" + member.getPort()); } return hazelcastConfig; }
Example 6
Source File: HazelcastWorkQueue.java From telekom-workflow-engine with MIT License | 5 votes |
@Override public void start(){ String hcInstanceName = config.getClusterHazelcastName(); hcInstance = Hazelcast.getHazelcastInstanceByName( hcInstanceName ); if (hcInstance == null) { log.info( "Didn't find an existing Hazelcast instance by name " + hcInstanceName + ". Starting our own instance!" ); Config hcConfig = new Config(); // Unfortunately, using the following line does not yet apply during the Hazelcast // initialization such that Hazelcast initalization log output ends up at stout. // This propblem is resolved by setting a system property as shown below. // hcConfig.setProperty( "hazelcast.logging.type", "slf4j" ); System.setProperty( "hazelcast.logging.class", "com.hazelcast.logging.Slf4jFactory" ); hcConfig.setProperty( "hazelcast.jmx", "true" ); hcConfig.setProperty( "hazelcast.shutdownhook.enabled", "false" ); hcConfig.setInstanceName( hcInstanceName ); hcConfig.getGroupConfig().setName( config.getClusterName() ); hcConfig.getNetworkConfig().getJoin().getMulticastConfig().setEnabled( true ); hcConfig.getNetworkConfig().getJoin().getMulticastConfig().setMulticastGroup( config.getClusterMulticastGroup() ); hcConfig.getNetworkConfig().getJoin().getMulticastConfig().setMulticastPort( config.getClusterMulticastPort() ); hcConfig.getNetworkConfig().getJoin().getMulticastConfig().setMulticastTimeToLive( config.getClusterMulticastTtl() ); hcInstance = Hazelcast.newHazelcastInstance( hcConfig ); isLocalHcInstance.set( true ); } else { log.info( "Found an existing Hazelcast instance by name " + hcInstanceName + ". Using that." ); } isStarted.set( true ); log.info( "Started queue" ); }
Example 7
Source File: SpringBootAdminHazelcastApplication.java From spring-boot-admin with Apache License 2.0 | 5 votes |
@Bean public Config hazelcastConfig() { // This map is used to store the events. // It should be configured to reliably hold all the data, // Spring Boot Admin will compact the events, if there are too many MapConfig eventStoreMap = new MapConfig(DEFAULT_NAME_EVENT_STORE_MAP).setInMemoryFormat(InMemoryFormat.OBJECT) .setBackupCount(1).setEvictionPolicy(EvictionPolicy.NONE) .setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100)); // This map is used to deduplicate the notifications. // If data in this map gets lost it should not be a big issue as it will atmost // lead to // the same notification to be sent by multiple instances MapConfig sentNotificationsMap = new MapConfig(DEFAULT_NAME_SENT_NOTIFICATIONS_MAP) .setInMemoryFormat(InMemoryFormat.OBJECT).setBackupCount(1).setEvictionPolicy(EvictionPolicy.LRU) .setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100)); Config config = new Config(); config.addMapConfig(eventStoreMap); config.addMapConfig(sentNotificationsMap); config.setProperty("hazelcast.jmx", "true"); // WARNING: This setups a local cluster, you change it to fit your needs. config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig(); tcpIpConfig.setEnabled(true); tcpIpConfig.setMembers(singletonList("127.0.0.1")); return config; }
Example 8
Source File: KeyUtilsTest.java From hazelcast-simulator with Apache License 2.0 | 5 votes |
@BeforeClass public static void beforeClass() { Config config = new Config(); config.setProperty("hazelcast.partition.count", "" + PARTITION_COUNT); hz = newHazelcastInstance(config); HazelcastInstance remoteInstance = newHazelcastInstance(config); warmupPartitions(hz); warmupPartitions(remoteInstance); ClientConfig clientconfig = new ClientConfig(); clientconfig.setProperty("hazelcast.partition.count", "" + PARTITION_COUNT); client = HazelcastClient.newHazelcastClient(clientconfig); }
Example 9
Source File: GenericTypesTest.java From hazelcast-simulator with Apache License 2.0 | 5 votes |
@BeforeClass public static void beforeClass() { Config config = new Config(); config.setProperty("hazelcast.partition.count", "" + PARTITION_COUNT); hz = Hazelcast.newHazelcastInstance(config); }
Example 10
Source File: HazelcastConfig.java From tutorials with MIT License | 5 votes |
@Bean public Config hazelcast() { MapConfig eventStoreMap = new MapConfig("spring-boot-admin-event-store").setInMemoryFormat(InMemoryFormat.OBJECT) .setBackupCount(1) .setEvictionPolicy(EvictionPolicy.NONE) .setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100)); MapConfig sentNotificationsMap = new MapConfig("spring-boot-admin-application-store").setInMemoryFormat(InMemoryFormat.OBJECT) .setBackupCount(1) .setEvictionPolicy(EvictionPolicy.LRU) .setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100)); Config config = new Config(); config.addMapConfig(eventStoreMap); config.addMapConfig(sentNotificationsMap); config.setProperty("hazelcast.jmx", "true"); config.getNetworkConfig() .getJoin() .getMulticastConfig() .setEnabled(false); TcpIpConfig tcpIpConfig = config.getNetworkConfig() .getJoin() .getTcpIpConfig(); tcpIpConfig.setEnabled(true); tcpIpConfig.setMembers(Collections.singletonList("127.0.0.1")); return config; }
Example 11
Source File: StompToStompThreadedRequestReplyReconnect.java From hazelcastmq with Apache License 2.0 | 4 votes |
/** * Constructs and executes the example. * * @throws Exception if there is an unexpected error */ public StompToStompThreadedRequestReplyReconnect() throws Exception { // Create a Hazelcast instance. Config config = new Config(); config.setProperty("hazelcast.logging.type", "slf4j"); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance(config); try { // Create the HazelcaseMQ instance. HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hazelcast); HazelcastMQInstance mqInstance = HazelcastMQ .newHazelcastMQInstance(mqConfig); // Create a Stomp server. HazelcastMQStompConfig stompConfig = new HazelcastMQStompConfig( mqInstance); stompConfig.setPort(STOMP_PORT); HazelcastMQStompInstance stompServer = HazelcastMQStomp. newHazelcastMQStompInstance(stompConfig); log.info("Stomp server is now listening on port: " + stompConfig.getPort()); // Create the backend worker. Backend backend = new Backend(); Thread t = new Thread(backend); t.start(); // Send a bunch of messages that need replies. for (int i = 0; i < 50; ++i) { // Create a Stomp client. StompClient stompClient = new StompClient("localhost", STOMP_PORT); stompClient.connect(); // Subscribe to the reply queue. StompClient.QueuingFrameListener msgListener = new StompClient.QueuingFrameListener(); Frame frame = FrameBuilder.subscribe(REPLY_QUEUE, "sub-2").build(); stompClient.subscribe(frame, msgListener); log.info("Sending request frame number {}", i); // Build and send the request. frame = FrameBuilder.send(REQUEST_QUEUE, "Request " + i).header( "correlation-id", UUID.randomUUID().toString()).header("reply-to", REPLY_QUEUE).build(); stompClient.send(frame); // Wait for the reply. frame = msgListener.poll(2, TimeUnit.SECONDS); if (frame == null) { log.warn("Did not get a reply frame!"); } else { log.info("Got reply frame: {}", frame.getBodyAsString()); } // Shutdown the client. stompClient.disconnect(); } // Shutdown the backend worker. backend.shutdown = true; t.join(); // Shutdown the server. log.info("Shutting down STOMP server."); stompServer.shutdown(); } finally { // Shutdown Hazelcast. hazelcast.getLifecycleService().shutdown(); } }
Example 12
Source File: HazelcastConsulSessionReplicationConfiguration.java From GreenSummer with GNU Lesser General Public License v2.1 | 4 votes |
@Bean @ConditionalOnProperty(name = "summer.hazelcast.consul.enabled", havingValue = "true", matchIfMissing = false) public Config hazlecastConsulConfig() throws Exception { Config config = new XmlConfigBuilder().build(); // final SpringManagedContext springManagedContext = new SpringManagedContext(); springManagedContext.setApplicationContext(applicationContext); config.setManagedContext(springManagedContext); // // Use Consul for discovery instead of multicast with the help of this: // https://github.com/bitsofinfo/hazelcast-consul-discovery-spi // config.setProperty("hazelcast.discovery.enabled", Boolean.TRUE.toString()); if(healthCheckType==HEALTHCHECKTYPE.HTTP) { config.setProperty("hazelcast.http.healthcheck.enabled", Boolean.TRUE.toString()); } config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); config.getNetworkConfig().setPublicAddress(InetAddress.getByName(discoveryHostName).getHostAddress()); DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig( new ConsulDiscoveryStrategyFactory()); discoveryStrategyConfig.addProperty(ConsulDiscoveryConfiguration.CONSUL_HOST.key(), this.consulHost); discoveryStrategyConfig.addProperty(ConsulDiscoveryConfiguration.CONSUL_PORT.key(), this.consulPort); discoveryStrategyConfig.addProperty(ConsulDiscoveryConfiguration.CONSUL_SERVICE_TAGS.key(), this.serviceTags); discoveryStrategyConfig.addProperty(ConsulDiscoveryConfiguration.CONSUL_SERVICE_NAME.key(), this.servicePrefix + this.appName); discoveryStrategyConfig.addProperty(ConsulDiscoveryConfiguration.CONSUL_HEALTHY_ONLY.key(), true); discoveryStrategyConfig.addProperty(ConsulDiscoveryConfiguration.CONSUL_DISCOVERY_DELAY_MS.key(), this.configurationDelay); discoveryStrategyConfig.addProperty(ConsulDiscoveryConfiguration.CONSUL_REGISTRATOR.key(), LocalDiscoveryNodeRegistrator.class.getName()); ObjectNode jsonRegistratorConfig = JsonNodeFactory.instance.objectNode(); jsonRegistratorConfig.put(LocalDiscoveryNodeRegistrator.CONFIG_PROP_PREFER_PUBLIC_ADDRESS, true); switch(healthCheckType) { case HTTP: jsonRegistratorConfig.put(BaseRegistrator.CONFIG_PROP_HEALTH_CHECK_PROVIDER,HttpHealthCheckBuilder.class.getName()); jsonRegistratorConfig.put(HttpHealthCheckBuilder.CONFIG_PROP_HEALTH_CHECK_HTTP, "http://#MYIP:#MYPORT/hazelcast/health"); jsonRegistratorConfig.put(HttpHealthCheckBuilder.CONFIG_PROP_HEALTH_CHECK_HTTP_INTERVAL_SECONDS, healthCheckInterval); log.debug("Hazelcast HTTP health check set up (run every {} secs)", healthCheckInterval); break; case TCP: jsonRegistratorConfig.put(BaseRegistrator.CONFIG_PROP_HEALTH_CHECK_PROVIDER,TcpHealthCheckBuilder.class.getName()); jsonRegistratorConfig.put(TcpHealthCheckBuilder.CONFIG_PROP_HEALTH_CHECK_TCP, "#MYIP:#MYPORT"); jsonRegistratorConfig.put(TcpHealthCheckBuilder.CONFIG_PROP_HEALTH_CHECK_TCP_INTERVAL_SECONDS, healthCheckInterval); log.debug("Hazelcast TCP health check set up (run every {} secs)", healthCheckInterval); break; default: log.warn("What are you doing here, my oh my!"); break; } // Scripts are executed on the consul server, so they are consul-host // dependent, meh // jsonRegistratorConfig.put(BaseRegistrator.CONFIG_PROP_HEALTH_CHECK_PROVIDER, // ScriptHealthCheckBuilder.class.getName()); // jsonRegistratorConfig.put(ScriptHealthCheckBuilder.CONFIG_PROP_HEALTH_CHECK_SCRIPT, // "nc -z #MYIP #MYPORT"); // jsonRegistratorConfig.put(ScriptHealthCheckBuilder.CONFIG_PROP_HEALTH_CHECK_SCRIPT_INTERVAL_SECONDS, // 10); discoveryStrategyConfig.addProperty(ConsulDiscoveryConfiguration.CONSUL_REGISTRATOR_CONFIG.key(), jsonRegistratorConfig.toString()); config.getNetworkConfig().getJoin().getDiscoveryConfig().getDiscoveryStrategyConfigs() .add(discoveryStrategyConfig); log.info("Hazelcast configured to use Consul for discovery"); // Apply custom configurations, if necessary if(hazelcastConfigurers!=null) { for(HazelcastConfigurer hazelcastConfigurer: hazelcastConfigurers) { log.debug("Applying HazelcastConfigurer {}", hazelcastConfigurer.getClass().getName()); hazelcastConfigurer.configure(config); } } return config; }
Example 13
Source File: StompWithExternalClient.java From hazelcastmq with Apache License 2.0 | 4 votes |
public StompWithExternalClient() throws Exception { // Create a shutdown anchor to shut things down cleanly. File anchorFile = new File("stomper_example_anchor.lck"); anchorFile.delete(); anchorFile.createNewFile(); anchorFile.deleteOnExit(); // Create a Hazelcast instance. Config config = new Config(); config.setProperty("hazelcast.logging.type", "slf4j"); HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance(config); try { // Create the HazelcaseMQ instance. HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hazelcast); HazelcastMQInstance mqInstance = HazelcastMQ .newHazelcastMQInstance(mqConfig); // Create a Stomp server. HazelcastMQStompConfig stompConfig = new HazelcastMQStompConfig( mqInstance); HazelcastMQStompInstance stompServer = HazelcastMQStomp. newHazelcastMQStompInstance(stompConfig); log.info("Stomp server is now listening on port: " + stompConfig.getPort()); log.info("Remove file " + anchorFile.getName() + " to shutdown."); while (anchorFile.exists()) { Thread.sleep(1000); } log.info("Shutting down Stomper."); stompServer.shutdown(); } finally { hazelcast.getLifecycleService().shutdown(); } }
Example 14
Source File: StompToStompOneWayTransaction.java From hazelcastmq with Apache License 2.0 | 4 votes |
public StompToStompOneWayTransaction() throws Exception { // Create a Hazelcast instance. Config config = new Config(); config.setProperty("hazelcast.logging.type", "slf4j"); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance(config); try { // Create the HazelcaseMQ instance. HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hazelcast); HazelcastMQInstance mqInstance = HazelcastMQ .newHazelcastMQInstance(mqConfig); // Create a Stomp server. HazelcastMQStompConfig stompConfig = new HazelcastMQStompConfig( mqInstance); HazelcastMQStompInstance stompServer = HazelcastMQStomp. newHazelcastMQStompInstance(stompConfig); log.info("Stomp server is now listening on port: " + stompConfig.getPort()); // Create a Stomp client. StompClient stompClient = new StompClient("localhost", stompConfig. getPort()); stompClient.connect(); // Create a Stomp client to poll. StompClient stompClient2 = new StompClient("localhost", stompConfig. getPort()); stompClient2.connect(); // Subscribe to a queue. StompClient.QueuingFrameListener msgListener = new StompClient.QueuingFrameListener(); Frame frame = FrameBuilder.subscribe("/queue/demo.test", "1").build(); stompClient2.subscribe(frame, msgListener); // Start a transaction final String transactionId = "tx1"; frame = FrameBuilder.begin(transactionId).build(); stompClient.begin(frame); // Send a message on that queue. frame = FrameBuilder.send("/queue/demo.test", "Hello World!") .header(org.mpilone.yeti.Headers.TRANSACTION, transactionId).build(); stompClient.send(frame); // Now try to consume that message. We shouldn't get anything because the // transaction hasn't been committed. frame = msgListener.poll(2, TimeUnit.SECONDS); Assert.isNull(frame, "Received unexpected frame!"); // Now commit the transaction. frame = FrameBuilder.commit(transactionId).build(); stompClient.commit(frame); // Now try to consume that message. We shouldn't get anything because the // transaction hasn't been committed. frame = msgListener.poll(2, TimeUnit.SECONDS); Assert.notNull(frame, "Did not receive unexpected frame!"); log.info("Got expected frame: " + frame.getBodyAsString()); // Shutdown the client. stompClient.disconnect(); stompClient2.disconnect(); // Shutdown the server. log.info("Shutting down STOMP server."); stompServer.shutdown(); } finally { // Shutdown Hazelcast. hazelcast.getLifecycleService().shutdown(); } }
Example 15
Source File: StompToJmsOneWay.java From hazelcastmq with Apache License 2.0 | 4 votes |
public StompToJmsOneWay() throws Exception { // Create a Hazelcast instance. Config config = new Config(); config.setProperty("hazelcast.logging.type", "slf4j"); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance(config); try { // Create the HazelcaseMQ instance. HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hazelcast); HazelcastMQInstance mqInstance = HazelcastMQ .newHazelcastMQInstance(mqConfig); // Create a Stomp server. HazelcastMQStompConfig stompConfig = new HazelcastMQStompConfig( mqInstance); HazelcastMQStompInstance stompServer = HazelcastMQStomp. newHazelcastMQStompInstance(stompConfig); log.info("Stomp server is now listening on port: " + stompConfig.getPort()); // Create a Stomp client. StompClient stompClient = new StompClient("localhost", stompConfig. getPort()); stompClient.connect(); // Send a message to a queue. Frame frame = FrameBuilder.send("/queue/demo.test", "Hello World!") .build(); stompClient.send(frame); // Now create a JMS consumer to consume that message. HazelcastMQJmsConfig jmsConfig = new HazelcastMQJmsConfig(); jmsConfig.setHazelcastMQInstance(mqInstance); HazelcastMQJmsConnectionFactory connectionFactory = new HazelcastMQJmsConnectionFactory( jmsConfig); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue("demo.test"); MessageConsumer consumer = session.createConsumer(destination); Message msg = consumer.receive(5000); Assert.notNull(msg, "Did not get required message."); Assert.isTrue(msg instanceof TextMessage, "Did not get correct message type."); log.info("Got expected JMS message: " + ((TextMessage) msg).getText()); // Shutdown the JMS consumer consumer.close(); session.close(); connection.close(); // Shutdown the client. stompClient.disconnect(); // Shutdown the server. log.info("Shutting down STOMP server."); stompServer.shutdown(); } finally { // Shutdown Hazelcast. hazelcast.getLifecycleService().shutdown(); } }
Example 16
Source File: StompToStompThreadedRequestReply.java From hazelcastmq with Apache License 2.0 | 4 votes |
public StompToStompThreadedRequestReply() throws Exception { // Create a Hazelcast instance. Config config = new Config(); config.setProperty("hazelcast.logging.type", "slf4j"); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance(config); try { // Create the HazelcaseMQ instance. HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hazelcast); HazelcastMQInstance mqInstance = HazelcastMQ .newHazelcastMQInstance(mqConfig); // Create a Stomp server. HazelcastMQStompConfig stompConfig = new HazelcastMQStompConfig( mqInstance); stompConfig.setPort(STOMP_PORT); HazelcastMQStompInstance stompServer = HazelcastMQStomp. newHazelcastMQStompInstance(stompConfig); log.info("Stomp server is now listening on port: " + stompConfig.getPort()); // Create the backend worker. Backend backend = new Backend(); Thread t = new Thread(backend); t.start(); // Create a Stomp client. StompClient stompClient = new StompClient("localhost", STOMP_PORT); stompClient.connect(); // Subscribe to the reply queue. StompClient.QueuingFrameListener msgListener = new StompClient.QueuingFrameListener(); Frame frame = FrameBuilder.subscribe(REPLY_QUEUE, "sub-2").build(); stompClient.subscribe(frame, msgListener); // Send a bunch of messages that need replies. for (int i = 0; i < 100; ++i) { log.info("Sending request frame number {}", i); // Build and send the request. frame = FrameBuilder.send(REQUEST_QUEUE, "Request " + i).header( "correlation-id", UUID.randomUUID().toString()).header("reply-to", REPLY_QUEUE).build(); stompClient.send(frame); // Wait for the reply. frame = msgListener.poll(2, TimeUnit.SECONDS); if (frame == null) { log.warn("Did not get a reply frame!"); } else { log.info("Got reply frame: {}", frame.getBodyAsString()); } } // Shutdown the backend worker. backend.shutdown = true; t.join(); // Shutdown the client. stompClient.disconnect(); // Shutdown the server. log.info("Shutting down STOMP server."); stompServer.shutdown(); } finally { // Shutdown Hazelcast. hazelcast.getLifecycleService().shutdown(); } }
Example 17
Source File: StompToStompOneWay.java From hazelcastmq with Apache License 2.0 | 4 votes |
public StompToStompOneWay() throws Exception { // Create a Hazelcast instance. Config config = new Config(); config.setProperty("hazelcast.logging.type", "slf4j"); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance(config); try { // Create the HazelcaseMQ instance. HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hazelcast); HazelcastMQInstance mqInstance = HazelcastMQ .newHazelcastMQInstance(mqConfig); // Create a Stomp server. HazelcastMQStompConfig stompConfig = new HazelcastMQStompConfig( mqInstance); HazelcastMQStompInstance stompServer = HazelcastMQStomp. newHazelcastMQStompInstance(stompConfig); log.info("Stomp server is now listening on port: " + stompConfig.getPort()); // Create a Stomp client. StompClient stompClient = new StompClient("localhost", stompConfig. getPort()); stompClient.connect(); // Subscribe to a queue. StompClient.QueuingFrameListener msgListener = new StompClient.QueuingFrameListener(); Frame frame = FrameBuilder.subscribe("/queue/demo.test", "1").build(); stompClient.subscribe(frame, msgListener); // Send a message on that queue. frame = FrameBuilder.send("/queue/demo.test", "Hello World!").build(); stompClient.send(frame); // Now consume that message. frame = msgListener.poll(3, TimeUnit.SECONDS); Assert.notNull(frame, "Did not receive expected frame!"); log.info("Got frame: " + frame.getBodyAsString()); // Shutdown the client. stompClient.disconnect(); // Shutdown the server. log.info("Shutting down STOMP server."); stompServer.shutdown(); } finally { // Shutdown Hazelcast. hazelcast.getLifecycleService().shutdown(); } }
Example 18
Source File: HazelcastLeaderAutoConfigurationTests.java From spring-cloud-cluster with Apache License 2.0 | 4 votes |
@Bean public Config hazelcastConfig() { Config config = new Config(); config.setProperty("foo", "bar"); return config; }
Example 19
Source File: HazelcastManager.java From lumongo with Apache License 2.0 | 4 votes |
public void init(Set<HazelcastNode> nodes, String hazelcastName) throws Exception { // force Hazelcast to use log4j int hazelcastPort = localNodeConfig.getHazelcastPort(); Config cfg = new Config(); cfg.setProperty(GroupProperty.LOGGING_TYPE.getName(), "log4j"); // disable Hazelcast shutdown hook to allow LuMongo to handle cfg.setProperty(GroupProperty.SHUTDOWNHOOK_ENABLED.getName(), "false"); cfg.setProperty(GroupProperty.REST_ENABLED.getName(), "false"); cfg.getGroupConfig().setName(hazelcastName); cfg.getGroupConfig().setPassword(hazelcastName); cfg.getNetworkConfig().setPortAutoIncrement(false); cfg.getNetworkConfig().setPort(hazelcastPort); cfg.setInstanceName("" + hazelcastPort); cfg.getManagementCenterConfig().setEnabled(false); NetworkConfig network = cfg.getNetworkConfig(); JoinConfig joinConfig = network.getJoin(); joinConfig.getMulticastConfig().setEnabled(false); joinConfig.getTcpIpConfig().setEnabled(true); for (HazelcastNode node : nodes) { joinConfig.getTcpIpConfig().addMember(node.getAddress() + ":" + node.getHazelcastPort()); } hazelcastInstance = Hazelcast.newHazelcastInstance(cfg); self = hazelcastInstance.getCluster().getLocalMember(); hazelcastInstance.getCluster().addMembershipListener(this); hazelcastInstance.getLifecycleService().addLifecycleListener(this); log.info("Initialized hazelcast"); Set<Member> members = hazelcastInstance.getCluster().getMembers(); Member firstMember = members.iterator().next(); if (firstMember.equals(self)) { log.info("Member is owner of cluster"); indexManager.loadIndexes(); } log.info("Current cluster members: <" + members + ">"); indexManager.openConnections(members); initLock.writeLock().unlock(); }