i try to use hazelcast within my java application (Minecraft-Plugin)! On my computer, all works fine, but on my server the members will not connect to each other. Every member seems to form its own (ego) cluster instead of joining together.
I dont know why and i need help.
Here is my Hazlecast config:
Config config = new Config();
config.setClusterName("core");
NetworkConfig networkConfig = config.getNetworkConfig();
networkConfig.setPort(5900);
config.getSerializationConfig().addDataSerializableFactory(1, new UserSerializerFactory());
MapConfig mapConfig = new MapConfig();
mapConfig.setName("users");
mapConfig.setBackupCount(1);
mapConfig.setTimeToLiveSeconds(30*86400); //30 Tage
config.addMapConfig(mapConfig);
hazelcastMember = Hazelcast.newHazelcastInstance(config);
userMap = hazelcastMember.getMap("users");
It works fine on my pc but not on my server!
Default configuration uses multicast for discovery, and this is frequently blocked on some hardware types.
Try something like this
Config config = new Config();
TcpIpConfig tcpIpConfig = new TcpIpConfig()
.setEnabled(true)
.setMembers(List.of("127.0.0.1:5900"));
JoinConfig joinConfig = new JoinConfig()
.setMulticastConfig(new MulticastConfig().setEnabled(false))
.setTcpIpConfig(tcpIpConfig);
NetworkConfig networkConfig = new NetworkConfig().setJoin(joinConfig);
networkConfig.setPort(5900);
config.setNetworkConfig(networkConfig);
ie. Turn off Multicast, use TCP to the list of specified addresses
Related
I am new to Ignite and Kubernetes. I have a.Net Core 3.1 web application which is hosted Azure Linux App Service.
I followed the instructions (Apache Ignite Instructions Offical Site) and Apache Ignite could run on Azure Kubernetes. I could create a sample table and read-write actions worked successfully. Here is the screenshot of my success tests on PowerShell.
Please see the success test
Now, I try to connect Apache Ignite from my .net core web app but I couldn't make it.
My code is as below. I try to connect with IgniteConfiguration and SpringCfgXml, but both of them getting error.
private void Initialize()
{
var cfg = GetIgniteConfiguration();
_ignite = Ignition.Start(cfg);
InitializeCaches();
}
public IgniteConfiguration GetIgniteConfiguration()
{
var appSettingsJson = AppSettingsJson.GetAppSettings();
var igniteNodes = appSettingsJson["AppSettings:IgniteNodes"];
var nodeList = igniteNodes.Split(",");
var config = new IgniteConfiguration
{
Logger = new IgniteLogger(),
DiscoverySpi = new TcpDiscoverySpi
{
IpFinder = new TcpDiscoveryStaticIpFinder
{
Endpoints = nodeList
},
SocketTimeout = TimeSpan.FromSeconds(5)
},
IncludedEventTypes = EventType.CacheAll,
CacheConfiguration = GetCacheConfiguration()
};
return config;
}
The first error I get:
Apache.Ignite.Core.Common.IgniteException HResult=0x80131500
Message=Java class is not found (did you set IGNITE_HOME environment
variable?):
org/apache/ignite/internal/processors/platform/PlatformIgnition
Source=Apache.Ignite.Core
Also, I have no idea what I am gonna set for IGNITE_HOME, and username and secret to authentication.
Solution :
I finally connect the Ignite on Azure Kubernetes.
Here is my connection method.
public void TestConnection()
{
var cfg = new IgniteClientConfiguration
{
Host = "MyHost",
Port = 10800,
UserName = "user",
Password = "password"
};
using (IIgniteClient client = Ignition.StartClient(cfg))
{
var employeeCache1 = client.GetOrCreateCache<int, Employee>(
new CacheClientConfiguration(EmployeeCacheName, typeof(Employee)));
employeeCache1.Put(1, new Employee("Bilge Wilson", 12500, 1));
}
}
To find to host IP, user name and client secret please check the below images.
Client Id and Secret
IP Addresses
Note: I don't need to set any IGNITE_HOME ana JAVA_HOME variable.
The simplest way is to download Apache Ignite binary distribution (of the same version as one that you use), unzip it to a directory, and point IGNITE_HOME environment variable or IgniteConfiguration.IgniteHome configuration property to unzipped apache-ignite-n.n.n-bin/ directory absolute path.
We support doing that automatically for Windows-hosted apps but not for Linux-based deployments.
I have an IMap, with Journal enabled.
Using a client (Hazelcast, or Jet), I would like to get the full map, and get all the subsequent updates to enrich the Map.
How could I achieve this?
If do a .getMap(), and then call getJournalMap() or .addEntryListener(), I am concerned with the possibility of missing updates in between the getMap() and addEntryListener() call.
Is there are more intuitive way to get full map+updates?
Thanks
What you are looking for is Continues Query Cache feature of Hazelcast. Please see https://docs.hazelcast.org/docs/3.11/manual/html-single/index.html#continuous-query-cache
Below is a sample usage from client
HazelcastInstance instance = Hazelcast.newHazelcastInstance();
QueryCacheConfig queryCacheConfig = new QueryCacheConfig("cache");
PredicateConfig predicateConfig = new PredicateConfig().setImplementation((Predicate) entry -> true);
queryCacheConfig.setPredicateConfig(predicateConfig);
ClientConfig clientConfig = new ClientConfig();
clientConfig.addQueryCacheConfig("map", queryCacheConfig);
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
IMap<Object, Object> map = client.getMap("map");
QueryCache<Object, Object> cache = map.getQueryCache("cache");
Currently the event journal does not expose a public API for reading the event journal in Hazelcast IMDG. The event journal can be used to stream event data to Hazelcast Jet, so it should be used in conjunction with Hazelcast Jet. You can see some examples here: https://github.com/hazelcast/hazelcast-jet-code-samples/tree/0.7-maintenance/event-journal
I have one case which works on JBoss 4.2.
Client login (with JAAS, ClientLoginModule)
Client get JMX connection from JBoss JMX server
Client call mbean API;
Server will check current caller/principal is, whether he/she has the enough privilege to do the action.
Now with Wildfly 9, we do the similar thing, moreover, we have set the username/password when getting JMX connection.
// urlString likes:service:jmx:remote://localhost:9999
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
Map<String, Object> env = new HashMap<String, Object>();
String[] creds = new String[2];
creds[0] = username_;
creds[1] = password_;
env.put(JMXConnector.CREDENTIALS, creds);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, env);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
However, at step3, JMX server find current caller/principal is null.
Do you know why? Or how to resolve this.
Are there any interceptors for JMX just like EJB?
I have defined "static" hazelcast configuration:
#Bean
public Config getHazelcastConfig() {
final Config config = new Config();
config.setProperty("hazelcast.logging.type", "slf4j");
final GroupConfig groupConfig = new GroupConfig();
groupConfig.setName("projectName");
groupConfig.setPassword("projectPassword");
config.setGroupConfig(groupConfig);
final NetworkConfig networkConfig = new NetworkConfig();
final TcpIpConfig tcpIpConfig = new TcpIpConfig();
final String[] members = "10.0.0.2".split(",");
for (String member : members) {
tcpIpConfig.addMember(member);
}
tcpIpConfig.setConnectionTimeoutSeconds(5);
final JoinConfig joinConfig = networkConfig.getJoin();
joinConfig.getAwsConfig().setEnabled(false);
joinConfig.getMulticastConfig().setEnabled(false);
joinConfig.setTcpIpConfig(tcpIpConfig);
joinConfig.getTcpIpConfig().setEnabled(true);
joinConfig.getTcpIpConfig().setConnectionTimeoutSeconds(5);
config.setNetworkConfig(networkConfig);
config.setInstanceName("projectInstanceName");
return config;
}
Where "10.0.0.2" is my localhost ip. I want only one instance of hazelcast added to my tcpIpConfig members. My friend is sitting in the same network and has IP with number "10.0.0.3". He is lazy to change password and group name from property file shared on git and is connecting to my cluster. Why he is able to connect to my cluster? How I can prevent this?
Yesss, #Sachin. You are right. After adding
securityCfg.setEnabled(true);
to hazelcast configuration passwords and logins are checked.
Second problem I had with multiple hazelcast instances on localhost was related with hibernate. When using hazelcast as second level cache in hibernate there is created hazelcast member. It can be turned on/off by:
properties.setProperty("hibernate.cache.hazelcast.use_native_client", "false");
or
properties.setProperty("hibernate.cache.hazelcast.use_native_client", "true");
I was wondering if there is an example usage of the AddressResolver interface in apache ignite.
I was trying to 'bind' my local IP addresses (e.g. 192.168.10.101) to my external IP address using the AddressResolver interface, but without luck.
When I do that the Ignite server just hangs (no output from the debug either)
My code for starting the server is:
TcpDiscoverySpi spi = new TcpDiscoverySpi();
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
ipFinder.setAddresses(ipaddresses);
spi.setIpFinder(ipFinder);
spi.setAddressResolver(new IotAddressResolver());
IgniteConfiguration cfg = new IgniteConfiguration();
// Override default discovery SPI.
cfg.setDiscoverySpi(spi);
System.setProperty("IGNITE_QUIET", "false");
// Start Ignite node.
ignite = Ignition.start(cfg);
My implementation for AddressResolver is:
public class IotAddressResolver implements AddressResolver {
#Override
public Collection<InetSocketAddress> getExternalAddresses(
InetSocketAddress internalAddresses) throws IgniteCheckedException {
String host = "XX.XX.XX.XX";
Collection<InetSocketAddress> result = new ArrayList<InetSocketAddress>();
result.add(new InetSocketAddress(host, internalAddresses.getPort()));
return result;
}
}
The last line of the ignite debug log is:
WARNING: Timed out waiting for message to be read (most probably, the reason is in long GC pauses on remote node) [curTimeout=9989]
I will appreciate any help. Thank you
Can you provide more details about your deployment and what you're trying to achieve with the help of address resolver? How many physical hosts and Ignite nodes do you have? Are they located in different networks with the router between them?
I dont know if this is the best way to handle this but I managed to start igntie as local server. I am setting my local ip and port like this:
System.setProperty("IGNITE_QUIET", "false");
TcpDiscoverySpi spi = new TcpDiscoverySpi();
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
TcpCommunicationSpi commSpi = new TcpCommunicationSpi();
// Set initial IP addresses.
ipFinder.setAddresses(ipaddresses);
spi.setIpFinder(ipFinder);
// Override local port.
commSpi.setLocalPort(47501);
commSpi.setLocalAddress("XX.XX.XX.XX");
commSpi.setLocalPortRange(50);
IgniteConfiguration cfg = new IgniteConfiguration();
// Override default communication SPI.
cfg.setCommunicationSpi(commSpi);
cfg.setDiscoverySpi(spi);
cfg.setAddressResolver(new IotAddressResolver());
cfg.setClientMode(true);
// Start Ignite node
ignite = Ignition.start(cfg);
Where XX.XX.XX.XX is my local IP address