use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project spring-integration by spring-projects.
the class AbstractMongoDbMessageStoreTests method testAddThenRemoveWithStringPayload.
@Test
@MongoDbAvailable
public void testAddThenRemoveWithStringPayload() throws Exception {
cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
MessageStore store = getMessageStore();
Message<?> messageToStore = MessageBuilder.withPayload("Hello").build();
store.addMessage(messageToStore);
Message<?> retrievedMessage = store.getMessage(messageToStore.getHeaders().getId());
assertNotNull(retrievedMessage);
store.removeMessage(retrievedMessage.getHeaders().getId());
retrievedMessage = store.getMessage(messageToStore.getHeaders().getId());
assertNull(retrievedMessage);
}
use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project spring-cloud-connectors by spring-cloud.
the class MongoDbFactoryCreator method create.
@Override
public MongoDbFactory create(MongoServiceInfo serviceInfo, ServiceConnectorConfig config) {
try {
MongoClientOptions.Builder mongoOptionsToUse = getMongoOptions((MongoDbFactoryConfig) config);
SimpleMongoDbFactory mongoDbFactory = createMongoDbFactory(serviceInfo, mongoOptionsToUse);
return configure(mongoDbFactory, (MongoDbFactoryConfig) config);
} catch (UnknownHostException e) {
throw new ServiceConnectorCreationException(e);
} catch (MongoException e) {
throw new ServiceConnectorCreationException(e);
}
}
use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project spring-cloud-connectors by spring-cloud.
the class MongoDbFactoryCreator method createMongoDbFactory.
private SimpleMongoDbFactory createMongoDbFactory(MongoServiceInfo serviceInfo, MongoClientOptions.Builder mongoOptionsToUse) throws UnknownHostException {
MongoClientURI mongoClientURI = new MongoClientURI(serviceInfo.getUri(), mongoOptionsToUse);
MongoClient mongo = new MongoClient(mongoClientURI);
return new SimpleMongoDbFactory(mongo, mongoClientURI.getDatabase());
}
use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project oc-explorer by devgateway.
the class MongoTemplateConfig method mongoTemplate.
@Bean(autowire = Autowire.BY_NAME, name = "mongoTemplate")
public MongoTemplate mongoTemplate() throws Exception {
MongoTemplate template = new MongoTemplate(new SimpleMongoDbFactory(new MongoClientURI(properties.getUri())));
((MappingMongoConverter) template.getConverter()).setCustomConversions(customConversions);
return template;
}
use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project oc-explorer by devgateway.
the class MongoTemplateConfig method shadowMongoTemplate.
/**
* Creates a shadow template configuration by adding "-shadow" as postfix of database name.
* This is used to replicate the entire database structure in a shadow/temporary database location
*
* @return
* @throws Exception
*/
@Bean(autowire = Autowire.BY_NAME, name = "shadowMongoTemplate")
public MongoTemplate shadowMongoTemplate() throws Exception {
MongoTemplate template = new MongoTemplate(new SimpleMongoDbFactory(new MongoClientURI(properties.getUri() + SHADOW_POSTFIX)));
((MappingMongoConverter) template.getConverter()).setCustomConversions(customConversions);
return template;
}
Aggregations