2017-08-14 22 views
0

當我嘗試創建新的IgniteConfiguration實例時,我不斷收到空引用異常。這是我如何創建配置:「未將對象引用設置到對象的實例」我無法讓Apache Ignite.NET在我的.NET應用程序內正確啓動

var cfg = new IgniteConfiguration 
       { 
        // Explicitly configure TCP discovery SPI to provide list of initial nodes 
        // from the first cluster. 
        DiscoverySpi = new TcpDiscoverySpi 
        { 
         // Initial local port to listen to. 
         LocalPort = 49500, 
         // Changing local port range. This is an optional action. 
         LocalPortRange = 2, 
         IpFinder = new TcpDiscoveryStaticIpFinder 
         { 
          // Addresses and port range of the nodes from the first cluster. 
          // 127.0.0.1 can be replaced with actual IP addresses or host names. 
          // The port range is optional. 
          Endpoints = { "127.0.0.1:49500..49520" } 
         } 
        }, 
        // Explicitly configure TCP communication SPI changing 
        // local port number for the nodes from the first cluster. 
        CommunicationSpi = new TcpCommunicationSpi 
        { 
         LocalPort = 49100 
        } 
       }; 

細節沒有內部異常和消息的異常只是說

當我嘗試使用web.config配置啓動Ignite時,它將工作,除非我嘗試明確設置端口。例如,這是一個有效的配置:

<igniteConfiguration xmlns="http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection" localhost="127.0.0.1" peerAssemblyLoadingMode="CurrentAppDomain"> 
<atomicConfiguration atomicSequenceReserveSize="10" /> 
<AutoGenerateIgniteInstanceName>true</AutoGenerateIgniteInstanceName> 
<discoverySpi type="TcpDiscoverySpi" localPort="49500" localPortRange="2"> 
    <ipFinder type="TcpDiscoveryStaticIpFinder"> 
    <endpoints> 
     <string>127.0.0.1</string> 
     <string>127.0.0.1:49500..49502</string> 
    </endpoints> 
    </ipFinder> 
</discoverySpi> 

不過,我有必要不使用mutlicast廣播,我需要設置明確的端口。該配置最終使用一些默認端口。所以,根據我的文檔可以這樣做:

<igniteConfiguration xmlns="http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection" localhost="127.0.0.1" peerAssemblyLoadingMode="CurrentAppDomain"> 
<atomicConfiguration atomicSequenceReserveSize="10" /> 
<AutoGenerateIgniteInstanceName>true</AutoGenerateIgniteInstanceName> 
<discoverySpi type="TcpDiscoverySpi" localPort="49500" localPortRange="2"> 
    <ipFinder type="TcpDiscoveryStaticIpFinder"> 
    <endpoints> 
     <string>127.0.0.1</string> 
     <string>127.0.0.1:49500..49502</string> 
    </endpoints> 
    </ipFinder> 
</discoverySpi> 
<communicationSpi type="TcpCommunicationSpi" localPort="49500" localPortRange="2" /> 

明確設置端口49500,但使用此配置的應用程序不啓動,只是掛在Ignite.startFromConfiguration()的一步。

所以我不能使用web.config創建實例,也不能以編程方式啓動它,因爲空引用異常。

任何人有任何想法?

+0

再深入一點,我發現這個異常事實上是由構建TcpDiscoveryStaticIpFinder類引發的。這對我來說沒有任何意義,因爲當我反編譯它並查看構造函數的作用時,它看起來沒有任何作用。即使是基類構造函數也是空的。但我一定在做錯事。 – DKhanaf

+0

更新,所以我得到了編程配置的工作。顯然它不喜歡這個Endpoints = {「127.0.0.1:49500..49520」},但它可以很好地與Endpoints = new List {「127.0.0.1:49500..49520」} – DKhanaf

回答

0

Endpoints是一個地址列表,所以它應該被初始化爲new[] {...}。看到這裏的例子:https://apacheignite-net.readme.io/v2.1/docs/configuration#section-c-code

至於第二個問題,你試圖設置相同的發現和通信端口,這是沒有道理的。這是不同的協議,應該使用不同的,不相交的端口範圍。

+0

你能解釋什麼是在這種情況下溝通和發現之間的區別?如果我有節點A啓動並使用「通信」端口45900,這是否意味着要「發現」節點A的節點B將嘗試使用端口45900?或者我完全錯了嗎? – DKhanaf

+0

除非此行配置僅用於發現的不同端口。因此,節點A啓動並在兩個端口(一個用於發現(所以其他節點可以「發現」它)以及一個用於由 DKhanaf

+1

Ignite中的這兩種協議同時工作。發現用於維護集羣中的一致拓撲信息,用於任何其他消息(例如,緩存操作請求/響應)的通信。每個服務器節點必須綁定到這兩個協議的不同端口。所以端口範圍必須不同。 –

相關問題