-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add detection of non-compacted session topic (#1044)
- Loading branch information
Showing
39 changed files
with
1,606 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
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
74 changes: 74 additions & 0 deletions
74
...ain/java/io/aklivity/zilla/runtime/binding/mqtt/kafka/internal/MqttKafkaEventContext.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2021-2023 Aklivity Inc | ||
* | ||
* Licensed under the Aklivity Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* https://www.aklivity.io/aklivity-community-license/ | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package io.aklivity.zilla.runtime.binding.mqtt.kafka.internal; | ||
|
||
import static io.aklivity.zilla.runtime.binding.mqtt.kafka.internal.types.event.MqttKafkaEventType.NON_COMPACT_SESSIONS_TOPIC; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.time.Clock; | ||
|
||
import org.agrona.concurrent.AtomicBuffer; | ||
import org.agrona.concurrent.UnsafeBuffer; | ||
|
||
import io.aklivity.zilla.runtime.binding.mqtt.kafka.internal.types.String16FW; | ||
import io.aklivity.zilla.runtime.binding.mqtt.kafka.internal.types.event.EventFW; | ||
import io.aklivity.zilla.runtime.binding.mqtt.kafka.internal.types.event.MqttKafkaEventExFW; | ||
import io.aklivity.zilla.runtime.engine.EngineContext; | ||
import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; | ||
|
||
public class MqttKafkaEventContext | ||
{ | ||
private static final int EVENT_BUFFER_CAPACITY = 2048; | ||
|
||
private final AtomicBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); | ||
private final AtomicBuffer extensionBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); | ||
private final EventFW.Builder eventRW = new EventFW.Builder(); | ||
private final MqttKafkaEventExFW.Builder mqttKafkaEventExRW = new MqttKafkaEventExFW.Builder(); | ||
private final int mqttTypeId; | ||
private final int nonCompactSessionsTopicEventId; | ||
private final MessageConsumer eventWriter; | ||
private final Clock clock; | ||
|
||
public MqttKafkaEventContext( | ||
EngineContext context) | ||
{ | ||
this.mqttTypeId = context.supplyTypeId(MqttKafkaBinding.NAME); | ||
this.nonCompactSessionsTopicEventId = context.supplyEventId("binding.mqtt.kafka.non.compact.sessions.topic"); | ||
this.eventWriter = context.supplyEventWriter(); | ||
this.clock = context.clock(); | ||
} | ||
|
||
public void onMqttConnectionReset( | ||
long traceId, | ||
long bindingId, | ||
String16FW reason) | ||
{ | ||
MqttKafkaEventExFW extension = mqttKafkaEventExRW | ||
.wrap(extensionBuffer, 0, extensionBuffer.capacity()) | ||
.nonCompactSessionsTopic(e -> e | ||
.typeId(NON_COMPACT_SESSIONS_TOPIC.value()) | ||
.reason(reason)) | ||
.build(); | ||
EventFW event = eventRW | ||
.wrap(eventBuffer, 0, eventBuffer.capacity()) | ||
.id(nonCompactSessionsTopicEventId) | ||
.timestamp(clock.millis()) | ||
.traceId(traceId) | ||
.namespacedId(bindingId) | ||
.extension(extension.buffer(), extension.offset(), extension.limit()) | ||
.build(); | ||
eventWriter.accept(mqttTypeId, event.buffer(), event.offset(), event.limit()); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...n/java/io/aklivity/zilla/runtime/binding/mqtt/kafka/internal/MqttKafkaEventFormatter.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2021-2023 Aklivity Inc | ||
* | ||
* Licensed under the Aklivity Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* https://www.aklivity.io/aklivity-community-license/ | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package io.aklivity.zilla.runtime.binding.mqtt.kafka.internal; | ||
|
||
import org.agrona.DirectBuffer; | ||
|
||
import io.aklivity.zilla.runtime.binding.mqtt.kafka.internal.types.String16FW; | ||
import io.aklivity.zilla.runtime.binding.mqtt.kafka.internal.types.event.EventFW; | ||
import io.aklivity.zilla.runtime.binding.mqtt.kafka.internal.types.event.MqttKafkaEventExFW; | ||
import io.aklivity.zilla.runtime.binding.mqtt.kafka.internal.types.event.MqttKafkaResetMqttConnectionExFW; | ||
import io.aklivity.zilla.runtime.engine.Configuration; | ||
import io.aklivity.zilla.runtime.engine.event.EventFormatterSpi; | ||
|
||
public final class MqttKafkaEventFormatter implements EventFormatterSpi | ||
{ | ||
private static final String NON_COMPACT_SESSIONS_TOPIC_FORMAT = "NON COMPACT SESSIONS TOPIC - %s"; | ||
|
||
private final EventFW eventRO = new EventFW(); | ||
private final MqttKafkaEventExFW mqttKafkaEventExRO = new MqttKafkaEventExFW(); | ||
|
||
MqttKafkaEventFormatter( | ||
Configuration config) | ||
{ | ||
} | ||
|
||
public String format( | ||
DirectBuffer buffer, | ||
int index, | ||
int length) | ||
{ | ||
final EventFW event = eventRO.wrap(buffer, index, index + length); | ||
final MqttKafkaEventExFW extension = mqttKafkaEventExRO | ||
.wrap(event.extension().buffer(), event.extension().offset(), event.extension().limit()); | ||
String result = null; | ||
switch (extension.kind()) | ||
{ | ||
case NON_COMPACT_SESSIONS_TOPIC: | ||
{ | ||
MqttKafkaResetMqttConnectionExFW ex = extension.nonCompactSessionsTopic(); | ||
result = String.format(NON_COMPACT_SESSIONS_TOPIC_FORMAT, asString(ex.reason())); | ||
break; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
private static String asString( | ||
String16FW stringFW) | ||
{ | ||
String s = stringFW.asString(); | ||
return s == null ? "" : s; | ||
} | ||
} |
Oops, something went wrong.