How do I use Apache Ignite from two or more IIS ap

2019-07-21 05:28发布

I am new to Apache Ignite and trying to use Ignite within IIS websites and WCF services. My test case involves two IIS hosted WCF test services on one PC. I am instantiating Ignite in either of the two IIS applications and then trying to access from the other. So far this has not worked. Once Ignite starts in one IIS app, I get a "Default grid instance has already been started" from the other app, but the other app is not able to get a handle of the existing default grid instance.

I am running the code below from the Global.asax Application_Start of both IIS test applications. Hoping someone can give insight and point me in the right direction:

Random random = new Random();
short startCounter = 0;
Stopwatch sw = new Stopwatch();
sw.Start();
do
{
    Thread.Sleep( 1000 * random.Next( 10, 20 ) );
    IgniteEngine = Ignition.TryGetIgnite();
    startCounter++;
    if ( null == IgniteEngine )
    {
        LogHelper.Write( "{0}: CacheManager.InitializeCache attempt {1} to get a new ignite instance failed.".InvariantFormat( CommonSystemInfo.MachineName, startCounter ), "TraceLogger" );
    }

    if ( null == IgniteEngine )
    {
        try
        {
            IgniteEngine = Ignition.Start( new IgniteConfiguration
            {
                JvmClasspath = System.IO.Directory.GetFiles( System.Web.HttpContext.Current.Server.MapPath( @"~\bin\libs" ) ).Aggregate( ( x, y ) => x + ";" + y )
            } );
            if ( null != IgniteEngine )
            {
                LogHelper.Write( "{0}: CacheManager.InitializeCache success starting ignite after {1} attempts and {2} seconds".InvariantFormat( CommonSystemInfo.MachineName, startCounter, sw.Elapsed.TotalSeconds ), "TraceLogger" );
            }
        }
        catch ( Exception ex2 )
        {
            LogHelper.Write( "{0}: CacheManager.InitializeCache error while trying to start a new ignite instance. {1}".InvariantFormat( CommonSystemInfo.MachineName, ex2.GetAllMessages() ), "TraceLogger" );
        }
    }
}
while ( null == IgniteEngine && sw.Elapsed.TotalMinutes <= 2 );

1条回答
来,给爷笑一个
2楼-- · 2019-07-21 06:03

Looks like your services run within one IIS Application Pool, which means one process and different app domains. This means that there is a single JVM within the process, which causes Default grid instance has already been started error.

Your options are:

  • Use different IgniteConfiguration.GridName
  • Assign different IIS Application Pool to one of the services
  • Run both services within one application so that TryGetIgnite works and you don't have to start Ignite twice
查看更多
登录 后发表回答