
001/*- 002 * #%L 003 * HAPI FHIR Storage api 004 * %% 005 * Copyright (C) 2014 - 2025 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.jpa.subscription.channel.config; 021 022import ca.uhn.fhir.broker.api.IBrokerClient; 023import ca.uhn.fhir.broker.api.IChannelNamer; 024import ca.uhn.fhir.broker.impl.LinkedBlockingBrokerClient; 025import ca.uhn.fhir.jpa.subscription.channel.impl.LinkedBlockingChannelFactory; 026import ca.uhn.fhir.jpa.subscription.channel.impl.RetryPolicyProvider; 027import ca.uhn.fhir.jpa.subscription.channel.subscription.SubscriptionChannelFactory; 028import org.springframework.beans.factory.annotation.Autowired; 029import org.springframework.context.annotation.Bean; 030import org.springframework.context.annotation.Configuration; 031 032@Configuration 033public class SubscriptionChannelConfig { 034 035 /** 036 * We are autowiring this because we need to override retry policy 037 * in some tests 038 */ 039 @Autowired 040 private RetryPolicyProvider myRetryPolicyProvider; 041 042 /** 043 * Create a @Primary @Bean if you need a different implementation 044 */ 045 @Bean 046 public LinkedBlockingChannelFactory queueChannelFactory(IChannelNamer theChannelNamer) { 047 return new LinkedBlockingChannelFactory(theChannelNamer, myRetryPolicyProvider); 048 } 049 050 @Bean 051 public IBrokerClient brokerClient(IChannelNamer theChannelNamer) { 052 return new LinkedBlockingBrokerClient(theChannelNamer); 053 } 054 055 @Bean 056 public RetryPolicyProvider retryPolicyProvider() { 057 return new RetryPolicyProvider(); 058 } 059 060 @Bean 061 public SubscriptionChannelFactory subscriptionChannelFactory(IBrokerClient theBrokerClient) { 062 return new SubscriptionChannelFactory(theBrokerClient); 063 } 064 065 /** 066 * Create a @Primary @Bean if you need a different implementation 067 */ 068 @Bean 069 // Default implementation returns the name unchanged 070 public IChannelNamer channelNamer() { 071 return (theNameComponent, theChannelSettings) -> theNameComponent; 072 } 073}