Created
July 28, 2022 13:52
-
-
Save irajhedayati/caf491b6c191cc6e72351df945fe55d7 to your computer and use it in GitHub Desktop.
The main application to run Pub/Sub application which supports local emulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main { | |
def main(args: Array[String]): Unit = { | |
Using.resource(getSubscriber(args)) { subscriber => | |
subscriber.startAsync.awaitRunning() | |
subscriber.awaitTerminated() | |
} | |
} | |
def getSubscriber(args: Array[String]): SubscriberWrapper = { | |
val projectId = args(0) | |
val subscription = args(1) | |
val topic = args(2) | |
val localPubSubEndpoint = if (args.length == 4) Option(args(3)) else None | |
val publisher = PublisherFactory(projectId, topic, localPubSubEndpoint) | |
val processor = new Processor(publisher) | |
SubscriberWrapper(projectId, subscription, localPubSubEndpoint, processor) | |
} | |
class Processor(publisher: Publisher) extends MessageReceiver { | |
override def receiveMessage(message: PubsubMessage, consumer: AckReplyConsumer): Unit = { | |
println(message.getData.toStringUtf8) | |
publisher.publish(message) | |
consumer.ack() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment