You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I stumbled on this repo looking for some examples of Google Subscription API implementation and noticed how you parse a message in PaymentController. Instead, I would suggest you too look at spring integration where you get parsing out of the box and you can bypass decoding instead, you can just deserialze from json string.
Additionally, when you registered AndroidPublisher bean, you can potentially simplify authentication part. The way I did it, is I created a service account with managed permissions and store the credentials file in AWS SM
Sharing you example how I did below in case you want to do:
@Configuration
class GoogleConfig(
@Value("\${spring.cloud.gcp.pubsub.billing-subscription}")
private val billingSubscription: String,
private val awsSecretsManagerService: AwsSecretsManagerService
) {
private val jsonFactory = GsonFactory.getDefaultInstance()
private val httpTransport = GoogleNetHttpTransport.newTrustedTransport()
@Bean
fun androidPublisher(
credentialsProvider: CredentialsProvider
): AndroidPublisher {
return AndroidPublisher.Builder(httpTransport, jsonFactory, HttpCredentialsAdapter(credentialsProvider.credentials))
.setApplicationName("project-name")
.build()
}
@Bean
fun pubsubInputChannel(): MessageChannel {
return DirectChannel()
}
@Bean
fun messageChannelAdapter(
//Declaring a qualifier for a message handling defined in BillingSubscriber
@Qualifier("pubsubInputChannel") inputChannel: MessageChannel?,
pubSubTemplate: PubSubTemplate?
): PubSubInboundChannelAdapter {
val adapter = PubSubInboundChannelAdapter(pubSubTemplate, billingSubscription)
adapter.outputChannel = inputChannel
adapter.setAckMode(AckMode.MANUAL)
return adapter
}
@Bean
fun credentialsProvider(): CredentialsProvider {
val credentialsStream = awsSecretsManagerService.getSecrets().gcpCredentials.byteInputStream()
val credentials = GoogleCredentials.fromStream(credentialsStream)
return CredentialsProvider { credentials }
}
}
BillinSubscriber.kt
@Component
class BillingSubscriber(
private val objectMapper: ObjectMapper
) {
@Bean
@ServiceActivator(inputChannel = "pubsubInputChannel")
fun messageReceiver(): MessageHandler {
return MessageHandler { message ->
val messageString = String((message.payload as ByteArray))
val originalMessage = GcpPubSubHeaders.getOriginalMessage(message)
if (originalMessage.isPresent) {
val notification = objectMapper.readValue(messageString, DeveloperNotification::class.java)
// Handle published message
originalMessage.get().ack()
} else {
logger.error { "Message can not be acknowledged" }
}
}
}
}
Cheers
The text was updated successfully, but these errors were encountered:
Hey there,
I stumbled on this repo looking for some examples of Google Subscription API implementation and noticed how you parse a message in PaymentController. Instead, I would suggest you too look at spring integration where you get parsing out of the box and you can bypass decoding instead, you can just deserialze from json string.
Additionally, when you registered AndroidPublisher bean, you can potentially simplify authentication part. The way I did it, is I created a service account with managed permissions and store the credentials file in AWS SM
Sharing you example how I did below in case you want to do:
BillinSubscriber.kt
Cheers
The text was updated successfully, but these errors were encountered: