英文:
How to setup Tomcat Session Replication with Spring Boot embedded tomcat
问题
我还没有找到有关如何在使用Spring Boot的嵌入式Tomcat时以编程方式设置Tomcat会话复制的指南。甚至找到"tomcat-catalina-ha"依赖项也让我费了不少时间。
在非嵌入式Tomcat上设置时,我有一个可工作的Tomcat会话复制示例,但将其转换为Java配置一直没有成功。我查看了Hazelcast,但我需要的一些选项需要企业许可证。我还被告知将会话存储在传统数据库中不具有良好的可伸缩性。
我正在寻找一个实现使用嵌入式Tomcat的Tomcat会话复制的指南或示例项目。如果找不到,我对为什么一开始就没有指南感兴趣。
英文:
I haven't been able to find any guide on how to programmatically setup tomcat session replication when using an embedded tomcat with spring boot. It was even a hard time finding out about the "tomcat-catalina-ha" dependency.
I have a working Tomcat session replication example working when setup on a non-embedded tomcat, but converting it over to Java config hasn't been working. I looked into Hazelcast, but a few of the options I need require the enterprise license. I've also been told that storing sessions in a traditional database doesn't scale well.
I'm looking for a guide or example project that implements Tomcat session replication using an embedded tomcat. Barring that, I'd be interested in why there are no guides in the first place?
答案1
得分: 1
经过更多的研究,我找到了这个文档:
> 这里列出的清单是唯一适合配置和操作问题的地方。
在浏览邮件列表存档时,我能够找到一个关于程序化集群配置的示例:https://marc.info/?l=tomcat-user&m=160220406421937&w=2
这个示例让我走了大部分的路程,我一直在上下文中设置我的集群:
@Configuration
public class MyConfig implements WebServerFactoryCustomize<TomcatServletWebServerFactory> {
@Override
public void customize(TomcatServletWebServerFactory factory) {
factory.addContextCustomizers(context -> {
//集群设置
SimpleTcpCluster simpleTcpCluster = new SimpleTcpCluster();
// 拦截器的顺序很重要
// 其余的设置细节,与邮件列表存档非常相似
// 确保为我创建DeltaManager
context.setDistributable(true);
// 关键点:
//context.setCluster(simpleTcpCluster);
// 修复代替context.setCluster
// context.getParent()是StandardHost的一个实例
// 如果您从server.xml中复制,也很明显
// 集群元素设置在主机上
context.getParent().setCluster(simpleTcpCluster);
// 通过在“主机”上设置它,它允许启动早期识别它以启动集群。
});
}
当我在上下文中设置集群时,实际上从未启动任何集群元素。
我还要注意,在调查这个问题时,我发现了一篇文章(2013年),展示了如何在使用嵌入式Tomcat时加载server.xml
,尽管我没有尝试过。
最后要注意的是,我使用了“StaticMembershipService”而不是多播方式,或者“StaticMembershipInterceptor”。
英文:
So after more research, I found this documentation:
> The list listed here is the only place that configuration and how-to questions belong, ever.
Looking through the mailing list archive, I was able to find one example of programmatic cluster configuration: https://marc.info/?l=tomcat-user&m=160220406421937&w=2
It was able to take me most of the way, I had been setting my cluster on the context via:
@Configuration
public class MyConfig implements WebServerFactoryCustomize<TomcatServletWebServerFactory> {
@Override
public void customize(TomcatServletWebServerFactory factory) {
factory.addContextCustomizers(context -> {
//cluster setup
SimpleTcpCluster simpleTcpCluster = new SimpleTcpCluster();
// order of your interceptors does matter fyi
// rest of setup details, very similar to mailing list archive
// Make sure the DeltaManager is created for me
context.setDistributable(true);
// The key point:
//context.setCluster(simpleTcpCluster);
// The fix instead of context.setCluster
// context.getParent() is an instance of StandardHost
// And if you are coping from a server.xml, it's also clear
// that the cluster element is set on the host
context.getParent().setCluster(simpleTcpCluster);
// Basically by setting it on the `host`, it allows the startup to
// recognize it early enough to start the cluster up.
});
}
When I set the cluster on the context, none of the cluster elements were ever actually started.
I would also note that when investigating this, I found an article(2013) showing how to load a server.xml
when using an embedded tomcat, although I didn't not try it.
Final note: I used the StaticMembershipService
vs the multicast stuff, or the StaticMembershipInterceptor
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论