Skip to content

Commit

Permalink
add redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
DC2-DanielKrueger committed Nov 12, 2024
1 parent 72575be commit 09802a6
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.hivemq.edge.HiveMQCapabilityService;
import com.hivemq.edge.ModulesAndExtensionsService;
import com.hivemq.extension.sdk.api.annotations.NotNull;
import com.hivemq.extension.sdk.api.services.publish.PublishService;
import com.hivemq.extensions.core.HandlerService;
import com.hivemq.extensions.core.PersistencesService;
import com.hivemq.extensions.core.RestComponentsService;
Expand Down Expand Up @@ -105,6 +106,11 @@ public AfterHiveMQStartBootstrapServiceImpl(
return delegate.eventService();
}

@Override
public @NotNull PublishService publishService() {
return delegate.publishService();
}

@Override
public @NotNull ProtocolAdapterManager protocolAdapterManager() {
return protocolAdapterManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.hivemq.adapter.sdk.api.events.EventService;
import com.hivemq.bootstrap.ioc.Persistences;
import com.hivemq.extension.sdk.api.annotations.NotNull;
import com.hivemq.extension.sdk.api.services.publish.PublishService;
import com.hivemq.extensions.core.HandlerService;
import com.hivemq.extensions.core.RestComponentsService;

Expand All @@ -31,4 +32,8 @@ public interface CompleteBootstrapService extends PersistenceBootstrapService {

@NotNull
EventService eventService();

@NotNull
PublishService publishService();

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.hivemq.configuration.service.ConfigurationService;
import com.hivemq.edge.HiveMQCapabilityService;
import com.hivemq.extension.sdk.api.annotations.NotNull;
import com.hivemq.extension.sdk.api.services.publish.PublishService;
import com.hivemq.extensions.core.HandlerService;
import com.hivemq.extensions.core.PersistencesService;
import com.hivemq.extensions.core.RestComponentsService;
Expand All @@ -38,6 +39,7 @@ public class CompleteBootstrapServiceImpl implements CompleteBootstrapService {
private final @NotNull RestComponentsService restComponentsService;
private final @NotNull HandlerService handlerService;
private final @NotNull EventService eventService;
private final @NotNull PublishService publishService;
private final @NotNull PersistenceBootstrapService delegate;

@Inject
Expand All @@ -46,12 +48,14 @@ public CompleteBootstrapServiceImpl(
final @NotNull Persistences persistences,
final @NotNull RestComponentsService restComponentsService,
final @NotNull HandlerService handlerService,
final @NotNull EventService eventService) {
final @NotNull EventService eventService,
final @NotNull PublishService publishService) {
this.delegate = delegate;
this.persistences = persistences;
this.restComponentsService = restComponentsService;
this.handlerService = handlerService;
this.eventService = eventService;
this.publishService = publishService;
}

@Override
Expand Down Expand Up @@ -109,6 +113,11 @@ public CompleteBootstrapServiceImpl(
return eventService;
}

@Override
public @NotNull PublishService publishService() {
return publishService;
}

@Override
public @NotNull EdgeCoreFactoryService edgeCoreFactoryService() {
return delegate.edgeCoreFactoryService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public class PublishBuilderImpl implements PublishBuilder {
@NotNull
private final SecurityConfigurationService securityConfigurationService;

@NotNull
@Inject
public PublishBuilderImpl(@NotNull final ConfigurationService configurationService) {
this.mqttConfigurationService = configurationService.mqttConfiguration();
Expand All @@ -101,9 +100,16 @@ public PublishBuilder fromPublish(@NotNull final PublishPacket publish) {
throw new DoNotImplementException(PublishPacket.class.getSimpleName());
}

return fromComplete(publish.getQos(), publish.getRetain(), publish.getTopic(), publish.getPayloadFormatIndicator(),
publish.getMessageExpiryInterval(), publish.getResponseTopic(), publish.getCorrelationData(),
publish.getContentType(), publish.getPayload(), publish.getUserProperties());
return fromComplete(publish.getQos(),
publish.getRetain(),
publish.getTopic(),
publish.getPayloadFormatIndicator(),
publish.getMessageExpiryInterval(),
publish.getResponseTopic(),
publish.getCorrelationData(),
publish.getContentType(),
publish.getPayload(),
publish.getUserProperties());
}

@NotNull
Expand All @@ -116,22 +122,55 @@ public PublishBuilder fromPublish(@NotNull final Publish publish) {
throw new DoNotImplementException(Publish.class.getSimpleName());
}

return fromComplete(publish.getQos(), publish.getRetain(), publish.getTopic(), publish.getPayloadFormatIndicator(),
publish.getMessageExpiryInterval(), publish.getResponseTopic(), publish.getCorrelationData(),
publish.getContentType(), publish.getPayload(), publish.getUserProperties());
return fromComplete(publish.getQos(),
publish.getRetain(),
publish.getTopic(),
publish.getPayloadFormatIndicator(),
publish.getMessageExpiryInterval(),
publish.getResponseTopic(),
publish.getCorrelationData(),
publish.getContentType(),
publish.getPayload(),
publish.getUserProperties());
}

public @NotNull PublishBuilder fromPublish(@NotNull final PUBLISH publish) {
Preconditions.checkNotNull(publish, "publish must not be null");
this.qos = publish.getQoS().toQos();
this.retain(publish.isRetain());
if (publish.getPayloadFormatIndicator() != null) {
this.payloadFormatIndicator = publish.getPayloadFormatIndicator().toPayloadFormatIndicator();
}
this.messageExpiryInterval(publish.getMessageExpiryInterval());
this.responseTopic(publish.getResponseTopic());
if (publish.getCorrelationData() != null) {
this.correlationData(ByteBuffer.wrap(publish.getCorrelationData()));
}

this.contentType(publish.getContentType());
if (publish.getPayload() != null) {
this.payload = ByteBuffer.wrap(publish.getPayload());

}
for (final UserProperty userProperty : publish.getUserProperties().asList()) {
this.userProperty(userProperty.getName(), userProperty.getValue());
}
return this;
}


@NotNull
private PublishBuilder fromComplete(@NotNull final Qos qos,
final boolean retain,
@NotNull final String topic,
@NotNull final Optional<PayloadFormatIndicator> payloadFormatIndicator,
@NotNull final Optional<Long> messageExpiryInterval,
@NotNull final Optional<String> responseTopic,
@NotNull final Optional<ByteBuffer> correlationData,
@NotNull final Optional<String> contentType,
@NotNull final Optional<ByteBuffer> payload,
@NotNull final UserProperties userProperties) {
private PublishBuilder fromComplete(
@NotNull final Qos qos,
final boolean retain,
@NotNull final String topic,
@NotNull final Optional<PayloadFormatIndicator> payloadFormatIndicator,
@NotNull final Optional<Long> messageExpiryInterval,
@NotNull final Optional<String> responseTopic,
@NotNull final Optional<ByteBuffer> correlationData,
@NotNull final Optional<String> contentType,
@NotNull final Optional<ByteBuffer> payload,
@NotNull final UserProperties userProperties) {
this.qos(qos);
this.retain(retain);
this.topic(topic);
Expand Down Expand Up @@ -192,7 +231,8 @@ public PublishBuilder payloadFormatIndicator(@Nullable final PayloadFormatIndica
@NotNull
@Override
public PublishBuilder messageExpiryInterval(final long messageExpiryInterval) {
PluginBuilderUtil.checkMessageExpiryInterval(messageExpiryInterval, mqttConfigurationService.maxMessageExpiryInterval());
PluginBuilderUtil.checkMessageExpiryInterval(messageExpiryInterval,
mqttConfigurationService.maxMessageExpiryInterval());
this.messageExpiryInterval = messageExpiryInterval;
return this;
}
Expand Down Expand Up @@ -247,7 +287,15 @@ public Publish build() {
messageExpiryInterval = mqttConfigurationService.maxMessageExpiryInterval();
}

return new PublishImpl(qos, retain, topic, payloadFormatIndicator, messageExpiryInterval, responseTopic,
correlationData, contentType, payload, UserPropertiesImpl.of(userPropertyBuilder.build()));
return new PublishImpl(qos,
retain,
topic,
payloadFormatIndicator,
messageExpiryInterval,
responseTopic,
correlationData,
contentType,
payload,
UserPropertiesImpl.of(userPropertyBuilder.build()));
}
}

0 comments on commit 09802a6

Please sign in to comment.