Skip to content

Commit

Permalink
Merge pull request #26 from ShareChat/update-fork-courier
Browse files Browse the repository at this point in the history
Update fork courier
  • Loading branch information
pulakdp authored Nov 20, 2024
2 parents cec1526 + bff7e47 commit 8eaa063
Show file tree
Hide file tree
Showing 84 changed files with 898 additions and 263 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '16.x'
node-version: '18.x'
- name: Check Build Website
run: |
cd docs
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '16.x'
node-version: '18.x'

- name: Build website
run: |
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTION.md → CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ GO-JEK Tech
[6]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
[7]: https://help.github.com/articles/using-pull-requests
[8]: https://github.com/diffplug/spotless
[9]: https://github.com/Kotlin/binary-compatibility-validator
[9]: https://github.com/Kotlin/binary-compatibility-validator
8 changes: 5 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
compileSdk 34

namespace = "com.gojek.courier.app"

defaultConfig {
applicationId "com.gojek.courier.app"
minSdkVersion 21
targetSdkVersion 31
targetSdkVersion 34
versionCode 1
versionName "1.0"
multiDexEnabled true
Expand Down Expand Up @@ -62,6 +63,7 @@ dependencies {

implementation project(':courier-stream-adapter-rxjava2')
implementation project(':courier-message-adapter-gson')
implementation project(':courier-message-adapter-text')
implementation project(':courier-message-adapter-moshi')
implementation project(':courier-message-adapter-protobuf')
implementation project(':adaptive-keep-alive')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package com.gojek.courier.app.data.network

import com.gojek.courier.QoS
import com.gojek.courier.annotation.Callback
import com.gojek.courier.annotation.Data
import com.gojek.courier.annotation.Path
import com.gojek.courier.annotation.Send
import com.gojek.courier.annotation.Subscribe
import com.gojek.courier.annotation.SubscribeMultiple
import com.gojek.courier.annotation.TopicMap
import com.gojek.courier.annotation.Unsubscribe
import com.gojek.courier.app.data.network.model.Message
import com.gojek.courier.callback.SendMessageCallback
import io.reactivex.Observable

interface CourierService {
@Send(topic = "{topic}", qos = QoS.ONE)
fun publish(@Path("topic") topic: String, @Data message: Message)
fun publish(@Path("topic") topic: String, @Data message: Message, @Callback callback: SendMessageCallback)

@Subscribe(topic = "{topic}")
fun subscribe(@Path("topic") topic: String): Observable<Message>
fun subscribe(@Path("topic") topic: String): Observable<String>

@Unsubscribe(topics = ["{topic}"])
fun unsubscribe(@Path("topic") topic: String)

@SubscribeMultiple
fun subscribeAll(@TopicMap topicMap: Map<String, QoS>): Observable<String>
}
49 changes: 45 additions & 4 deletions app/src/main/java/com/gojek/courier/app/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package com.gojek.courier.app.ui

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.gojek.chuckmqtt.external.MqttChuckConfig
import com.gojek.chuckmqtt.external.MqttChuckInterceptor
import com.gojek.chuckmqtt.external.Period
import com.gojek.courier.Courier
import com.gojek.courier.QoS
import com.gojek.courier.QoS.ZERO
import com.gojek.courier.app.R
import com.gojek.courier.app.data.network.CourierService
import com.gojek.courier.app.data.network.model.Message
import com.gojek.courier.callback.SendMessageCallback
import com.gojek.courier.logging.ILogger
import com.gojek.courier.messageadapter.gson.GsonMessageAdapterFactory
import com.gojek.courier.messageadapter.text.TextMessageAdapterFactory
import com.gojek.courier.streamadapter.rxjava2.RxJava2StreamAdapterFactory
import com.gojek.mqtt.auth.Authenticator
import com.gojek.mqtt.client.MqttClient
Expand All @@ -24,6 +29,7 @@ import com.gojek.mqtt.model.AdaptiveKeepAliveConfig
import com.gojek.mqtt.model.KeepAlive
import com.gojek.mqtt.model.MqttConnectOptions
import com.gojek.mqtt.model.ServerUri
import com.gojek.mqtt.model.Will
import com.gojek.workmanager.pingsender.WorkManagerPingSenderConfig
import com.gojek.workmanager.pingsender.WorkPingSenderFactory
import kotlinx.android.synthetic.main.activity_main.brokerIP
Expand Down Expand Up @@ -78,12 +84,37 @@ class MainActivity : AppCompatActivity() {
send.setOnClickListener {
courierService.publish(
topic = topic.text.toString(),
message = Message(123, message.text.toString())
message = Message(123, message.text.toString()),
callback = object : SendMessageCallback {
override fun onMessageSendTrigger() {
Log.d("Courier", "onMessageSendTrigger")
}

override fun onMessageWrittenOnSocket() {
Log.d("Courier", "onMessageWrittenOnSocket")
}

override fun onMessageSendSuccess() {
Log.d("Courier", "onMessageSendSuccess")
}

override fun onMessageSendFailure(error: Throwable) {
Log.d("Courier", "onMessageSendFailure")
}
}
)
}

subscribe.setOnClickListener {
courierService.subscribe(topic = topic.text.toString())
val topics = topic.text.toString().split(",")
val stream = if (topics.size == 1) {
courierService.subscribe(topic = topics[0])
} else {
val topicMap = mutableMapOf<String, QoS>()
for (topic in topics) { topicMap[topic] = ZERO }
courierService.subscribeAll(topicMap = topicMap)
}
stream.subscribe { Log.d("Courier", "Message received: $it") }
}

unsubscribe.setOnClickListener {
Expand All @@ -92,12 +123,21 @@ class MainActivity : AppCompatActivity() {
}

private fun connectMqtt(clientId: String, username: String, password: String, ip: String, port: Int) {

val will = Will(
topic = "last/will/topic",
message = "Client disconnected unexpectedly",
qos = QoS.ZERO,
retained = false
)

val connectOptions = MqttConnectOptions.Builder()
.serverUris(listOf(ServerUri(ip, port, if (port == 443) "ssl" else "tcp")))
.clientId(clientId)
.userName(username)
.password(password)
.cleanSession(false)
.will(will)
.keepAlive(KeepAlive(timeSeconds = 30))
.build()

Expand Down Expand Up @@ -129,19 +169,20 @@ class MainActivity : AppCompatActivity() {
),
inactivityTimeoutSeconds = 45,
activityCheckIntervalSeconds = 30,
connectPacketTimeoutSeconds = 5,
incomingMessagesTTLSecs = 60,
incomingMessagesCleanupIntervalSecs = 10,
maxInflightMessagesLimit = 1000,
),
pingSender = WorkPingSenderFactory.createMqttPingSender(applicationContext, WorkManagerPingSenderConfig())
pingSender = WorkPingSenderFactory.createMqttPingSender(applicationContext, WorkManagerPingSenderConfig(sendForcePing = true))
)
mqttClient = MqttClientFactory.create(this, mqttConfig)
mqttClient.addEventHandler(eventHandler)

val configuration = Courier.Configuration(
client = mqttClient,
streamAdapterFactories = listOf(RxJava2StreamAdapterFactory()),
messageAdapterFactories = listOf(GsonMessageAdapterFactory()),
messageAdapterFactories = listOf(TextMessageAdapterFactory(), GsonMessageAdapterFactory()),
logger = getLogger()
)
val courier = Courier(configuration)
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ plugins {
}

dependencies {
implementation("com.android.tools.build:gradle:7.0.3")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31")
implementation("com.android.tools.build:gradle:7.4.2")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.18.0")
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.5.0")
}
Expand Down
16 changes: 8 additions & 8 deletions buildSrc/src/main/kotlin/deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ object versions {
const val jacoco = "0.8.6"
const val detekt = "1.18.0"

const val kotlin = "1.4.30"
const val agp = "7.0.3"
const val kotlin = "1.6.21"
const val agp = "7.4.2"
const val jetifierProcessor = "1.0.0-beta10"
const val jfrogBuildInfoExtractor = "4.11.0"
const val jfrogBuildInfoExtractor = "4.23.4"
const val navigation = "2.1.0-rc01"
const val coroutines = "1.3.2"
const val broadcast = "1.0.0"
Expand All @@ -30,7 +30,7 @@ object versions {
const val materialVersion = "1.3.0"
const val annotationVersion = "1.2.0"
const val coreKtxVersion = "1.3.0"
const val apiValidator = "0.6.0"
const val apiValidator = "0.14.0"
const val workManager = "2.7.0"
}

Expand All @@ -45,11 +45,11 @@ object deps {
const val protobuf = "com.google.protobuf:protobuf-lite:3.0.0"

object build {
const val buildToolsVersion = "31.0.0"
const val compileSdkVersion = 31
const val buildToolsVersion = "33.0.1"
const val compileSdkVersion = 34
const val minSdkVersion = 21
const val sampleMinSdkVersion = 21
const val targetSdkVersion = 31
const val targetSdkVersion = 34
}

object test {
Expand Down Expand Up @@ -134,4 +134,4 @@ object deps {
const val runtime = "androidx.work:work-runtime:${versions.workManager}"
const val runtime_2_6_0 = "androidx.work:work-runtime:2.6.0"
}
}
}
3 changes: 0 additions & 3 deletions courier-core-android/api/courier-core-android.api
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
public final class com/gojek/courier/utils/extensions/PendingIntentExtensionsKt {
}

21 changes: 15 additions & 6 deletions courier-core/api/courier-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,26 @@ public abstract interface class com/gojek/courier/StreamAdapter$Factory {
public abstract fun create (Ljava/lang/reflect/Type;)Lcom/gojek/courier/StreamAdapter;
}

public final class com/gojek/courier/callback/NoOpSendMessageCallback : com/gojek/courier/callback/SendMessageCallback {
public static final field INSTANCE Lcom/gojek/courier/callback/NoOpSendMessageCallback;
public fun onMessageSendFailure (Ljava/lang/Throwable;)V
public fun onMessageSendSuccess ()V
public fun onMessageSendTrigger ()V
public fun onMessageWrittenOnSocket ()V
}

public abstract interface class com/gojek/courier/callback/SendMessageCallback {
public abstract fun onMessageSendFailure (Ljava/lang/Throwable;)V
public abstract fun onMessageSendSuccess ()V
public abstract fun onMessageSendTrigger ()V
public abstract fun onMessageWrittenOnSocket ()V
}

public final class com/gojek/courier/extensions/CollectionExtensionsKt {
public static final fun toImmutableMap (Ljava/util/Map;)Ljava/util/Map;
public static final fun toImmutableSet (Ljava/util/Set;)Ljava/util/Set;
}

public final class com/gojek/courier/extensions/TimeUnitExtensionsKt {
}

public abstract interface class com/gojek/courier/logging/ILogger {
public abstract fun d (Ljava/lang/String;Ljava/lang/String;)V
public abstract fun d (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
Expand All @@ -74,6 +86,3 @@ public abstract interface class com/gojek/courier/logging/ILogger {
public abstract fun w (Ljava/lang/String;Ljava/lang/Throwable;)V
}

public final class com/gojek/courier/utils/TypeUtils {
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.gojek.courier.callback

object NoOpSendMessageCallback : SendMessageCallback {
override fun onMessageSendTrigger() {
// no-op
}

override fun onMessageWrittenOnSocket() {
// no-op
}

override fun onMessageSendSuccess() {
// no-op
}

override fun onMessageSendFailure(error: Throwable) {
// no-op
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.gojek.courier.callback

interface SendMessageCallback {
fun onMessageSendTrigger()
fun onMessageWrittenOnSocket()
fun onMessageSendSuccess()
fun onMessageSendFailure(error: Throwable)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gojek.courier.extensions

import androidx.annotation.RestrictTo

@RestrictTo(RestrictTo.Scope.LIBRARY)
fun String.isWildCardTopic(): Boolean {
return startsWith("+/") || contains("/+/") || endsWith("/+") || equals("+") ||
endsWith("/#") || equals("#")
}
3 changes: 3 additions & 0 deletions courier/api/courier.api
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public final class com/gojek/courier/Courier$Configuration {
public fun toString ()Ljava/lang/String;
}

public abstract interface annotation class com/gojek/courier/annotation/Callback : java/lang/annotation/Annotation {
}

public abstract interface annotation class com/gojek/courier/annotation/Data : java/lang/annotation/Annotation {
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.gojek.courier.annotation

@MustBeDocumented
@Target(AnnotationTarget.VALUE_PARAMETER)
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
annotation class Callback
Loading

0 comments on commit 8eaa063

Please sign in to comment.