com.sitewhere.grpc.kafka.serdes.PreprocessedEventPayloadSerde Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sitewhere-grpc-kafka Show documentation
Show all versions of sitewhere-grpc-kafka Show documentation
SiteWhere gRPC Kafka Support
The newest version!
/**
* Copyright © 2014-2020 The SiteWhere Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sitewhere.grpc.kafka.serdes;
import java.util.Map;
import org.apache.kafka.common.serialization.Deserializer;
import org.apache.kafka.common.serialization.Serde;
import org.apache.kafka.common.serialization.Serdes.WrapperSerde;
import org.apache.kafka.common.serialization.Serializer;
import com.sitewhere.grpc.event.EventModelMarshaler;
import com.sitewhere.grpc.model.DeviceEventModel.GPreprocessedEventPayload;
import com.sitewhere.spi.SiteWhereException;
/**
* Kafka {@link Serde} implementation for gRPC preprocessed event payload
* message.
*/
public class PreprocessedEventPayloadSerde extends WrapperSerde {
public PreprocessedEventPayloadSerde() {
super(new PreprocessedEventPayloadSerializer(), new PreprocessedEventPayloadDeserializer());
}
/**
* Serializer for gRPC preprocessed event payload message.
*/
public static class PreprocessedEventPayloadSerializer implements Serializer {
/*
* @see
* org.apache.kafka.common.serialization.Serializer#configure(java.util.Map,
* boolean)
*/
@Override
public void configure(Map configs, boolean isKey) {
}
/*
* @see
* org.apache.kafka.common.serialization.Serializer#serialize(java.lang.String,
* java.lang.Object)
*/
@Override
public byte[] serialize(String topic, GPreprocessedEventPayload data) {
try {
return EventModelMarshaler.buildPreprocessedEventPayloadMessage(data);
} catch (SiteWhereException e) {
throw new RuntimeException("Unable to deserialize payload.", e);
}
}
/*
* @see org.apache.kafka.common.serialization.Serializer#close()
*/
@Override
public void close() {
}
}
/**
* Deserializer for gRPC preprocessed event payload message.
*/
public static class PreprocessedEventPayloadDeserializer implements Deserializer {
/*
* @see
* org.apache.kafka.common.serialization.Deserializer#configure(java.util.Map,
* boolean)
*/
@Override
public void configure(Map configs, boolean isKey) {
}
/*
* @see
* org.apache.kafka.common.serialization.Deserializer#deserialize(java.lang.
* String, byte[])
*/
@Override
public GPreprocessedEventPayload deserialize(String topic, byte[] data) {
try {
return EventModelMarshaler.parsePreprocessedEventPayloadMessage(data);
} catch (SiteWhereException e) {
throw new RuntimeException("Unable to deserialize payload.", e);
}
}
/*
* @see org.apache.kafka.common.serialization.Deserializer#close()
*/
@Override
public void close() {
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy