Created
July 5, 2020 09:25
-
-
Save ptupitsyn/a2c13f47e19ccfc9c0b548cf4d4fa629 to your computer and use it in GitHub Desktop.
Ignite.NET server + Ignite Java client with SQL query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.ignite.Ignite; | |
import org.apache.ignite.IgniteCache; | |
import org.apache.ignite.Ignition; | |
import org.apache.ignite.binary.BinaryBasicNameMapper; | |
import org.apache.ignite.cache.query.SqlFieldsQuery; | |
import org.apache.ignite.configuration.BinaryConfiguration; | |
import org.apache.ignite.configuration.IgniteConfiguration; | |
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; | |
import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder; | |
import java.util.Collections; | |
import java.util.List; | |
public class main { | |
public static void main(String[] args) { | |
IgniteConfiguration cfg = new IgniteConfiguration(); | |
// Enable client mode. | |
cfg.setClientMode(true); | |
// Setting up an IP Finder to ensure the client can locate the servers. | |
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder(); | |
ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500..47509")); | |
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder)); | |
// Configure Ignite to connect with .NET nodes | |
cfg.setBinaryConfiguration(new BinaryConfiguration() | |
.setNameMapper(new BinaryBasicNameMapper(true)) | |
.setCompactFooter(true)); | |
// Start Ignite in client mode. | |
Ignite ignite = Ignition.start(cfg); | |
IgniteCache c = ignite.cache("C"); | |
List all = c.query(new SqlFieldsQuery("select Name from Trade")).getAll(); | |
System.out.println(all); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using Apache.Ignite.Core; | |
using Apache.Ignite.Core.Binary; | |
using Apache.Ignite.Core.Cache.Affinity; | |
using Apache.Ignite.Core.Cache.Configuration; | |
using Apache.Ignite.Core.Events; | |
namespace IgniteSimpleNameMapperTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello World!"); | |
var ignite = Ignition.Start(DefaultIgniteConfig()); | |
var cache = ignite.GetCache<AffinityKey, Trade>("C"); | |
cache[new AffinityKey("foo", "bar")] = new Trade {Name = "test"}; | |
// Wait forever - this is a server node. | |
Thread.Sleep(-1); | |
} | |
public static IgniteConfiguration DefaultIgniteConfig() | |
{ | |
var queryEntity = new QueryEntity | |
{ | |
KeyTypeName = nameof(AffinityKey), | |
ValueType = typeof(Trade), | |
}; | |
return new IgniteConfiguration | |
{ | |
BinaryConfiguration = new BinaryConfiguration | |
{ | |
NameMapper = new BinaryBasicNameMapper {IsSimpleName = true}, | |
}, | |
IncludedEventTypes = EventType.All, | |
CacheConfiguration = new[] | |
{ | |
new CacheConfiguration | |
{ | |
Name = "C", | |
QueryEntities = new[] {queryEntity} | |
} | |
} | |
}; | |
} | |
} | |
public class Trade | |
{ | |
[QuerySqlField] public string Name { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment