简体   繁体   中英

Spring Session for Pivotal GemFire Multi-Session

We are trying for a solution of non-sticky session for a retailer across servers. Servers used are WebLogic 12.2.1.3 and TomcatEE 7.0.5. We are able to see sessions persisting across servers.

httpServletRequest.getSession() is at times trying to retrieve the session from the container rather than GemFire.

Also the session id we see in client cookie and server logs are different from what is being seen inside GemFire. Is this expected?

EDIT: The session id created inside GemFire is base64 encoded on the client browser. This would answer the above question.

Be sure that you have "enabled" Spring Session for Pivotal GemFire in all the (Spring Boot) application instances you have deployed across both WebLogic and TomcatEE. This is as simple as the following:

@SpringBootApplication
@EnableGemFireHttpSession
class MySpringBootWebApplication {

    public static void main(String[] args) {
        SpringApplication.run(MySpringBootApplication.class, args);
    }

    ...
}

@EnableGemFireHttpSession is key. Also make sure the app instances deployed in each WebLogic and TomcatEE are sharing the same Region in the backend Pivotal GemFire cluster, assuming there is a single GemFire cluster serving apps in both WebLogic and TomcatEE.

For instance, if you explicitly set the Region, using:

@EnableGemFireHttpSession(regionName = "MySessionRegion")

Make sure all app instances use the same Region name (ie "MySessionRegion"). Alternatively, as of SSDG 2.0.5.RELEASE the Region name can be configured using a property in Spring Boot's application.properties file:

spring.session.data.gemfire.session.region.name=MySessionRegion

Also, make sure all apps are configured to talk to the same GemFire cluster. This depends on the Pool that the Spring Session Region uses to talk to the GemFire cluster. The Pool name is configurable with the annotation, like so:

@EnableGemFireHttpSession(..., poolName = "SessionPool")

Then, you must configure the Pool for all app instances to connect to the same GemFire cluster, ideally with Locators, like so:

@Configuration class MyGemFireConfiguration {

@Bean("SessionPool")
PoolFactoryBean sessionPool() {

    PoolFactoryBean sessionPool = new PoolFactoryBean();

    sessionPool.setName("SessionPool");
    sessionPool.setLocators(Arrays.asList(new ConnectionEndpoint("host1", port1),
        new ConnectionEndpoint("host2", port2),
        ...,
        new ConnectionEndpoint("hostN", portN));

    return sessionPool;
}

...

}

Alternatively, you can configure the "DEFAULT" GemFire Pool, assuming the configured client PROXY Region storing Session state uses the "DEFAULT" Pool, which it will when no Pool is explicitly configured/named. For example .

The last thing to be mindful of is if you are using the GemFire WAN topology, with multiple sites where each site is serving a particular collection of apps segregated by app server, perhaps (ie WebLogic vs. TomcatEE). Then you must ensure that you have configured GemFire WAN appropriate to coordinate across your multiple GemFire clusters. This is beyond the scope of this answer and so I will encourage you to look at this .

Feel free to share any sample code, configuration and/or tests you have that might shed light on the problems you are experiencing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM