use of org.eclipse.kapua.service.datastore.model.MessageCreator in project kapua by eclipse.
the class MessageStoreServiceTest method testStore.
@Test
public void testStore() throws Exception {
KapuaId scopeId = new KapuaEid(BigInteger.valueOf(1));
long accountSerial = (new Date()).getTime();
AccountCreator accountCreator = this.getTestAccountCreator(scopeId, accountSerial);
MessageStoreService messageStoreService = locator.getService(MessageStoreService.class);
DatastoreObjectFactory dsObjectFactory = locator.getFactory(DatastoreObjectFactory.class);
MessageCreator messageCreator = dsObjectFactory.newMessageCreator();
Payload messagePayload = dsObjectFactory.newPayload();
Position messagePosition = dsObjectFactory.newPosition();
Map<String, Object> metrics = new HashMap<String, Object>();
Date now = new Date();
messageCreator.setTimestamp(now);
messageCreator.setReceivedOn(now);
String topicName = String.format("%s/CLIENT001/APP01", accountCreator.getName());
messageCreator.setTopic(topicName);
metrics.put("metric_long", 1L);
metrics.put("metric_string", "pippo");
messagePayload.setMetrics(metrics);
messagePayload.setCollectedOn(now);
messagePosition.setAltitude(1.0);
messagePosition.setTimestamp(now);
messagePayload.setPosition(messagePosition);
messagePayload.setMetrics(metrics);
messageCreator.setPayload(messagePayload);
// FIXME store fails fix it !!
// StorableId messageId = messageStoreService.store(scopeId, messageCreator);
//
// Message asserts
// assertNotNull(messageId);
// assertTrue(!messageId.toString().isEmpty());
}
use of org.eclipse.kapua.service.datastore.model.MessageCreator in project kapua by eclipse.
the class DataStorageMessageProcessor method processMessage.
/**
* Process a data message.
*/
@Override
public void processMessage(CamelKapuaMessage<?> message) {
metricStorageMessage.inc();
// data messages
try {
Context metricStorageDataSaveTimeContext = metricStorageDataSaveTime.time();
MessageCreator mc = datastoreObjectFactory.newMessageCreator();
messageStoreService.store(message.getMessage().getScopeId(), mc);
metricStorageDataSaveTimeContext.stop();
} catch (KapuaException e) {
metricStorageDataErrorMessage.inc();
logger.error("An error occurred while storing message: {}", e.getCode().toString());
}
}
Aggregations