首页 > 解决方案 > 将环境变量目标传递给 ErpCommand

问题描述

我已经定义了一个环境变量目标,我想将用户/密码传递给 ErpCommand。我只使用带有目标名称的 ErpConfigContext 参数,当然我得到错误:无法获取当前用户:用户未通过身份验证。我的目的地是这样定义的:

目的地: | [ {“名称”:“ErpQueryEndpoint”,网址:“ https://something.s4hana.ondemand.com ”,用户名:“用户”,密码:“pass”,“forwardAuthToken”:true,属性:[{key: "TrustAll",值:"true"}]}]

如果没有 Hystrix 命令,调用就可以正常工作,我想用 Hystrix 实现相同的结果。

标签: s4sdk

解决方案


Please try to also define an environment variable ALLOW_MOCKED_AUTH_HEADER with value true for running this locally / in non-production scenarios (or USE_MOCKED_TENANT & USE_MOCKED_USER).

This is needed because the Hystrix command is by default tenant and user-isolated. Alternatively, if you do not need this isolation and are fine with circuit breakers etc spanning across tenants and user, you can also modify the default Hystrix settings when defining your command by leveraging the class HystrixUtil. In the constructor of your command, use code similar to the following:

super(HystrixUtil.getDefaultErpCommandSetter(YourCommand.class)
    .andCommandKey(HystrixCommandKey.Factory.asKey(
        HystrixUtil.getGlobalKey(YourCommand.class))));

推荐阅读