All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.beetl.sql.saga.kafka.ByteSerializer Maven / Gradle / Ivy

The newest version!
package org.beetl.sql.saga.kafka;

import org.apache.kafka.common.serialization.Serializer;
import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream;
import org.beetl.sql.saga.common.SagaTransaction;

import java.io.*;

/**
 * 序列化到kafka,二进制
 * @author xiandafu
 */
public class ByteSerializer implements Serializer {

	@Override
	public byte[] serialize(String s, SagaTransaction sagaTransaction) {
		ByteArrayOutputStream ba=new ByteArrayOutputStream();
		ObjectOutputStream oos= null;
		try {
			oos = new ObjectOutputStream(ba);
			oos.writeObject(sagaTransaction);
			byte[] bytes=ba.toByteArray();
			return bytes;
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}




}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy