简体   繁体   English

使用dynamodb的tomcat会话管理器

[英]tomcat session manager using dynamodb

I am trying to use tomcat session manger with dynamoDB. 我正在尝试对dynamoDB使用tomcat会话管理器。

I was taking reference from this aws guide http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-tomcat-session-manager.html . 我正在从该AWS指南http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-tomcat-session-manager.html中获取参考。

they have mentioned in the guide that we have to use 他们在指南中提到了我们必须使用的

    <Context>
        <WatchedResource>WEB-INF/web.xml</WatchedResource>
        <Manager className="com.amazonaws.services.dynamodb.sessionmanager.DynamoDBSessionManager"
         awsAccessKey="myAccessKey"
         awsSecretKey="mySecretKey"
         createIfNotExist="true" />
    </Context>

so if i don't give any target region this by default will pick us-east-1(as its hardcoded in the .jar file mentioned in aws documention). 因此,如果我不提供任何目标区域,则默认情况下将选择us-east-1(因为其在aws文档中提到的.jar文件中进行了硬编码)。 and if i specify any region it will pick that region. 如果我指定任何区域,它将选择该区域。 but i have my application in multiple regions and want separate dynamo instances for each region. 但是我在多个区域中都有我的应用程序,并且希望每个区域都有单独的dynamo实例。 As for multiple regions session id's are not unique so i can't use the same dynamo instance for all the regions. 至于多个区域的会话ID并非唯一,因此我不能对所有区域都使用相同的dynamo实例。

How it can be done, any help will be appreciated. 如何做到,任何帮助将不胜感激。

Its better you create multiple DyanoDB clients, one for each region. 最好创建多个DyanoDB客户端,每个区域一个。 You should use some config/prop file, which contains the different aws access-key, secret and config and based on which you create the client at the application startups. 您应该使用一些config / prop文件,该文件包含不同的aws访问密钥,密钥和配置,并基于它们在应用程序启动时创建客户端。 And then use it according to your business logic. 然后根据您的业务逻辑使用它。

For example :- I am using the ProfileCredentialsProvider and below config file in my application, Which uses multiple dynamoDB clients. 例如: -我使用ProfileCredentialsProvider在我的应用程序,它使用多个dynamoDB客户及以下配置文件。

# AWS DynamoDB setting
mumDynamoDB:
  # profile name of aws IAM role which has access to dynamoDB
  profileName: mumdynamoDBdev
  region: ap-south-1 
OrgonDynamoDB:
  # profile name of aws IAM role which has access to dynamoDB
  profileName: OrgdynamoDBdev
  region: us-west-2

And below piece of code create clients based on region and profile. 在下面的代码段中,根据区域和个人资料创建客户端。

public static DynamoDB getDocClient(String profileName, String region) {
        // http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/creating-clients.html new way of
        // creating all the aws clients.
        // thread safe impl
        AmazonDynamoDB amazonDynamoDBClient = AmazonDynamoDBClientBuilder.standard()
                .withRegion(region)
                .withCredentials(new ProfileCredentialsProvider(profileName)).build();
        docClient = new DynamoDB(amazonDynamoDBClient);

        return docClient;
    } 

Then in application, based on your requirement you can use appropriate client. 然后在应用程序中,根据您的要求,您可以使用适当的客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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