我在调用外部服务的 Lambda 中使用 quarkus-oidc-client-filter,效果非常好。不幸的是,对 Lambda 的调用可能是突发的。当在一段安静期后发生大爆发时,我可以限制对外部服务令牌端点的调用速率。出于这个原因,我希望在 Lambda 之间共享令牌,并为此创建了一个令牌提供程序,遵循一些 Quarkus 示例。但是,当 Lambda 启动时,我的 filterRequest 上出现 ContextNotActiveException。我的 TokenProvider 签名是
@Provider
@Singleton
@Unremovable
@Priority(Priorities.AUTHENTICATION)
public class OidcClientRequestFilterShared extends AbstractTokensProducer implements ClientRequestFilter
以及伴随的错误
Caused by: javax.enterprise.context.ContextNotActiveException
at io.quarkus.arc.impl.ClientProxies.getDelegate(ClientProxies.java:46)
at io.quarkus.oidc.client.runtime.TokensProducer_ProducerMethod_produceTokens_494654c3bfa2346b017c24e2e2c4fcfc99087d0e_ClientProxy.arc$delegate(Unknown Source)
at io.quarkus.oidc.client.runtime.TokensProducer_ProducerMethod_produceTokens_494654c3bfa2346b017c24e2e2c4fcfc99087d0e_ClientProxy.getAccessToken(Unknown Source)
at com.acme.myapp.lambda.oidc.OidcClientRequestFilterShared.filter(OidcClientRequestFilterShared.java:52)
...
2022-01-27 12:35:02,037 INFO [com.acm.mya.lam.SendMessageResource] (main) Sending message to app service
2022-01-27 12:35:04,027 WARN [org.jbo.res.res.i18n] (main) RESTEASY002160: Provider instance com.acme.myapp.lambda.oidc.OidcClientRequestFilterShared is already registered. 2nd registration is being ignored.
javax.enterprise.context.ContextNotActiveException: javax.ws.rs.ProcessingException
javax.ws.rs.ProcessingException: javax.enterprise.context.ContextNotActiveException
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.filterRequest(ClientInvocation.java:780)
at org.jboss.resteasy.microprofile.client.impl.MpClientInvocation.filterRequest(MpClientInvocation.java:75)
...