Created
June 1, 2021 00:26
-
-
Save victorbrndls/2337c083239ce96030de375aefc69a83 to your computer and use it in GitHub Desktop.
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
val scope = CoroutineScope(Dispatchers.IO) | |
fun main() { | |
val channel = AndroidChannelBuilder | |
.forAddress("127.0.0.1", 9090) | |
.build() | |
val book = BookOuterClass.Book.newBuilder() | |
.setId(1) | |
.setTitle("gRPC In-Depth") | |
.build() | |
val createBookRequest = BookOuterClass.CreateBookRequest.newBuilder() | |
.setBook(book) | |
.build() | |
val stub = BookstoreGrpcKt.BookstoreCoroutineStub(channel) | |
scope.launch { | |
try { | |
stub.createBook(createBookRequest) | |
} catch (e: StatusException) { | |
// handle exception | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment