
com.alogic.rabbitmq.serializer.Content Maven / Gradle / Ivy
package com.alogic.rabbitmq.serializer;
import java.io.UnsupportedEncodingException;
import com.alogic.event.Event;
import com.alogic.event.EventBus;
import com.alogic.event.EventSerializer;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;
/**
* 序列化器
* @author yyduan
*
*/
public class Content extends EventSerializer.Abstract {
protected String encoding = "utf-8";
protected String evtType = "default";
protected boolean async = true;
@Override
public void configure(Properties p) {
encoding = PropertiesConstants.getString(p,"encoding",encoding);
evtType = PropertiesConstants.getString(p,"evt.type",evtType);
async = PropertiesConstants.getBoolean(p,"evt.async",async);
}
@Override
public byte[] serialize(String queue, Event evt) {
String content = evt.getProperty("content", "");
try {
return content.getBytes(encoding);
} catch (UnsupportedEncodingException e) {
return null;
}
}
@Override
public Event deserialize(String queue, byte[] data) {
try {
Event evt = EventBus.newEvent(evtType,async);
evt.setProperty("content", new String(data,encoding),true);
return evt;
} catch (UnsupportedEncodingException e) {
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy