Search in sources :

Example 1 with MessageCreator

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());
}
Also used : AccountCreator(org.eclipse.kapua.service.account.AccountCreator) DatastoreObjectFactory(org.eclipse.kapua.service.datastore.DatastoreObjectFactory) Position(org.eclipse.kapua.service.datastore.model.Position) HashMap(java.util.HashMap) MessageStoreService(org.eclipse.kapua.service.datastore.MessageStoreService) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) Date(java.util.Date) MessageCreator(org.eclipse.kapua.service.datastore.model.MessageCreator) Payload(org.eclipse.kapua.service.datastore.model.Payload) KapuaId(org.eclipse.kapua.model.id.KapuaId) Test(org.junit.Test)

Example 2 with MessageCreator

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());
    }
}
Also used : Context(com.codahale.metrics.Timer.Context) KapuaException(org.eclipse.kapua.KapuaException) MessageCreator(org.eclipse.kapua.service.datastore.model.MessageCreator)

Aggregations

MessageCreator (org.eclipse.kapua.service.datastore.model.MessageCreator)2 Context (com.codahale.metrics.Timer.Context)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 KapuaException (org.eclipse.kapua.KapuaException)1 KapuaEid (org.eclipse.kapua.commons.model.id.KapuaEid)1 KapuaId (org.eclipse.kapua.model.id.KapuaId)1 AccountCreator (org.eclipse.kapua.service.account.AccountCreator)1 DatastoreObjectFactory (org.eclipse.kapua.service.datastore.DatastoreObjectFactory)1 MessageStoreService (org.eclipse.kapua.service.datastore.MessageStoreService)1 Payload (org.eclipse.kapua.service.datastore.model.Payload)1 Position (org.eclipse.kapua.service.datastore.model.Position)1 Test (org.junit.Test)1