In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "how to build a multi-platform Ignite cluster". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Building a multi-platform Ignite cluster: Java+.NET
An Ignite cluster can consist of nodes launched on any platform it supports, including Java, .NET, and C++. This article describes how to run a .NET / Java cluster through NuGet and Maven
prerequisite
This article applies to .NET developers who are not familiar with Java, and vice versa, so it will be described in more detail. The following software will be used in this article:
Visual Studio 2015 (including NuGet; Free Community Edition)
IntelliJ IDEA (including Maven; free community edition).
target
Connect Java and .NET nodes
Using Java and .NET classes to access shared data in the Ignite cache through the same name and field
Run a continuous query to observe real-time data updates from another platform.
Java Project Settings
Start IntelliJ IDEA and click "Create New Project":
Select Maven and click "Next":
Enter Maven information, click "Next" and then "Finish":
When you are finished, you will see the pom.xml file opened by the new project:
Add Ignite dependencies for project fragments:
Org.apache.ignite ignite-core 1.7.0
IDEA may ask if you want to import project changes and click on any link:
Add the Demo class to src\ main\ java, as follows:
Import org.apache.ignite.Ignition;public class Demo {public static void main (String [] args) {Ignition.start ();}}
Run through Shift+F10, and then confirm that the node is started on the console of IDEA:
Terminate the program through Ctrl+F2 or the stop button.
.net project settings
Start Visual Studio and click File-> New-> Project:
Select Visual C #-> Windows-> Console Application:
Make sure the. NET Framework version 4 or above is selected above
Click "OK" and an empty console project will be generated.
Open the NuGet console: Menu-> Tools-> NuGet Package Manager-> Package Manager Console
Enter Install-Package Apache.Ignite:
Click enter, and a message such as Successfully installed 'Apache.Ignite 1.7.0' to IgniteMultiPlatform will be output.
Change the content of Program.cs to something like this:
Using System;using Apache.Ignite.Core;class Program {static void Main (string [] args) {Ignition.Start (); Console.ReadKey ();}}
Start the program through Ctrl-F5, and then confirm that the Ignite node has started in the console:
Adjust the configuration of Java nodes to discover .NET nodes
Now you can start the Java node in IDEA and the .NET node in Visual Studio at the same time, and the following error will be found in one of them:
IgniteSpiException: Local node's binary configuration is not equal to remote node's binary configuration [locBinaryCfg= {globSerializer=null, compactFooter=true, globIdMapper=org.apache.ignite.binary.BinaryBasicIdMapper}, rmtBinaryCfg=null]
This error means that the .NET node only supports BinaryBasicIdMapper and BinaryBasicNameMapper in BinaryConfiguration, and needs to be explicitly set in Java to change the Ignition.start (); line to the following code:
BinaryConfiguration binCfg = new BinaryConfiguration (); binCfg.setIdMapper (new BinaryBasicIdMapper ()); binCfg.setNameMapper (new BinaryBasicNameMapper ()); IgniteConfiguration cfg = new IgniteConfiguration (). SetBinaryConfiguration (binCfg); Ignition.start (cfg)
At this point, start both the Java and .NET nodes to verify that they can find each other:
[15:04:17] Topology snapshot [ver=2, servers=2, clients=0, CPUs=8, heap=7.1GB] exchanges data through Ignite cache
Now that the nodes are connected, a simple chat program will be written on each platform to demonstrate the exchange of data. The code is very simple because the API is the same and the language syntax is similar. First, define a class with exactly the same name and member.
Java Message class
Right-click the src\ main\ java project folder and select New-> Java Class, and enter the Message name as follows:
Public class Message {public Message (String author, String text) {this.author = author; this.text = text;} final String author; final String text;}. NET Message class
Right-click the project node of Solution Explorer, and then select Add-> Class... Enter the name of Message with the code as follows:
Class Message {public Message (string author, string text) {Author = author; Text = text;} public string Author {get;} public string Text {get;}}
The Basic mapper is case-sensitive and ignores namespaces (packages), so the two classes can be mapped to each other, injecting Message instances into the cache on one platform and getting them on the other. Now start writing the chat program itself, the logic is relatively simple: the user enters a chat message, then injects it into the cache, and the continuous query receives all cached update notifications and displays them.
Java chat program
Change the code of the main method to the following:
/ / Retrieve user nameSystem.out.print ("Hi, enter your name:"); Scanner consoleScanner = new Scanner (System.in); String name = consoleScanner.nextLine (); / / Get or create cacheIgniteCache cache = ignite.getOrCreateCache ("chat"); / / Initialize unique ID sequenceIgniteAtomicSequence messageId = ignite.atomicSequence ("chatId", 0, true); / / Set up continuous queryContinuousQuery qry = new ContinuousQuery (); qry.setLocalListener (iterable-> {/ / This will be invoked immediately on each cache update for (CacheEntryEvent)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.