Skip to content

Commit

Permalink
Fixed local axon mongo configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornharvold committed Jan 1, 2015
1 parent d5e334b commit cb7f584
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 210 deletions.
354 changes: 175 additions & 179 deletions bearchoke-backend/.idea/workspace.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.authentication.UserCredentials;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;

import javax.inject.Inject;
Expand Down Expand Up @@ -63,10 +64,13 @@ public Mongo mongo() throws UnknownHostException {
return new MongoClient(sa, options);
}

@Bean
@Bean(name = "mongoDbFactory")
public SimpleMongoDbFactory mongoDbFactory() throws Exception {
return new SimpleMongoDbFactory(mongo(), environment.getProperty("mongodb.database"));
}


@Bean(name = "axonMongoDbFactory")
public SimpleMongoDbFactory axonMongoDbFactory() throws Exception {
return mongoDbFactory();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bearchoke.platform.platform.base.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;

/**
* Created by Bjorn Harvold
* Date: 1/9/14
* Time: 11:55 PM
* Responsibility:
*/
@Configuration
@Profile("mongodb-cloud")
@PropertySource(value = "classpath:cqrs-cloud.properties")
public class AxonCQRSCloudConfig {

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.bearchoke.platform.platform.base.config;

import org.apache.commons.lang3.StringUtils;
import org.axonframework.commandhandling.CommandBus;
import org.axonframework.commandhandling.CommandDispatchInterceptor;
import org.axonframework.commandhandling.SimpleCommandBus;
Expand All @@ -34,6 +35,7 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.task.TaskExecutor;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.messaging.SubscribableChannel;
Expand All @@ -49,7 +51,10 @@
* Responsibility:
*/
@Configuration
public class CQRSConfig {
public class AxonCQRSConfig {

@Inject
private Environment environment;

@Inject
@Qualifier("threadPoolTaskExecutor")
Expand Down Expand Up @@ -102,8 +107,27 @@ public SpringMessagingEventBus eventBus() {

@Bean(name = "axonMongoTemplate")
public MongoTemplate axonMongoTemplate() {
// this is not good!! Axon doesn't support just using the mongoDbFactory that is supplied by the cloud connector
return new DefaultMongoTemplate(mongoDbFactory.getDb().getMongo(), "CloudFoundry_691iug0t_9kmtciq3", "domainevents", "snapshotevents", "axon", "axon".toCharArray());
MongoTemplate mongoTemplate;

String username = environment.getProperty("mongodb.axon.username");
String password = environment.getProperty("mongodb.axon.password");
String database = environment.getProperty("mongodb.axon.database");

if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password) && StringUtils.isNotBlank(database)) {
// this is not good!! Axon doesn't support just using the mongoDbFactory that is supplied by the cloud connector
mongoTemplate = new DefaultMongoTemplate(
mongoDbFactory.getDb().getMongo(),
database,
"domainevents",
"snapshotevents",
username,
password.toCharArray()
);
} else {
mongoTemplate = new DefaultMongoTemplate(mongoDbFactory.getDb().getMongo());
}

return mongoTemplate;
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bearchoke.platform.platform.base.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;

/**
* Created by Bjorn Harvold
* Date: 1/9/14
* Time: 11:55 PM
* Responsibility:
*/
@Configuration
@Profile("mongodb-local")
@PropertySource(value = "classpath:cqrs-local.properties")
public class AxonCQRSLocalConfig {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

mongodb.axon.username=axon
mongodb.axon.password=axon
mongodb.axon.database=CloudFoundry_691iug0t_9kmtciq3
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

mongodb.axon.username=
mongodb.axon.password=
mongodb.axon.database=
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.bearchoke.platform.api.todo.CreateToDoItemCommand;
import com.bearchoke.platform.api.todo.MarkToDoItemAsCompleteCommand;
import com.bearchoke.platform.api.todo.ToDoIdentifier;
import com.bearchoke.platform.platform.base.config.CQRSConfig;
import com.bearchoke.platform.platform.base.config.AxonCQRSConfig;
import com.bearchoke.platform.todo.config.ToDoConfig;
import com.bearchoke.platform.platform.base.config.RabbitMQLocalConfig;
import com.bearchoke.platform.platform.base.config.SchedulerConfig;
Expand All @@ -41,7 +41,7 @@ public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
SchedulerConfig.class,
RabbitMQLocalConfig.class,
CQRSConfig.class,
AxonCQRSConfig.class,
ToDoConfig.class
);

Expand Down
43 changes: 19 additions & 24 deletions bearchoke-frontend/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cb7f584

Please sign in to comment.