Skip to content

Commit

Permalink
Added charset when producing and consuming messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jbvanzuylen committed Dec 20, 2018
1 parent 72b9871 commit 43631cf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void received(final Consumer<byte[]> consumer, final Message<byte[]> mess
final Map<String, Object> data = new HashMap<String, Object>();
data.put("callback", new Callback(message.getMessageId()));
data.put("properties", message.getProperties());
data.put("message", new String(message.getData()));
data.put("message", new String(message.getData(), ENCODING_CHARSET));
this.getGateway().handleMessage(data);
}
catch (Throwable t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.primeoservices.cfgateway.pulsar;

import java.nio.charset.Charset;

import org.apache.pulsar.client.api.PulsarClientException;

/**
Expand All @@ -24,6 +26,8 @@
*/
public abstract class PulsarExchanger
{
protected static final Charset ENCODING_CHARSET = Charset.forName("UTF-8");

private PulsarGateway gateway;

private Logger log;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void postMessage(final Map<?, ?> data) throws Exception
final TypedMessageBuilder<byte[]> builder = this.producer.newMessage();
final Object properties = data.get(PROPERTIES_KEY);
PulsarUtils.setProperties(builder, (Map<?, ?>) properties);
builder.value(((String) message).getBytes());
builder.value(((String) message).getBytes(ENCODING_CHARSET));
builder.send();
}
}

0 comments on commit 43631cf

Please sign in to comment.