building a common message solution with mongodb at vertafore
DESCRIPTION
Vertafore offers a suite of software products to the insurance agencies, ranging from agency management system, workflow, connectivity and rating to producer solutions. With such a diverse products offerings with different technology stack, there is a growing need to have a common message solution that can provide for both end user notification type of message as well as inter production integration system level message. This talk will include an overview of the overall architecture, and an in-depth walk through of the main component, a “RESTful” web service(OData Services) implemented using asp.net webapi (C#, .NET). A real usage scenario of the system will be demoed.TRANSCRIPT
![Page 1: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/1.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.1
Building a Common Notification Solution with MongoDBJohn Gao | September 16, 2014
Steven Engelhart
![Page 2: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/2.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.2
Agenda
1 About Vertafore
2 Problem Statement
3 Design and Implementation
4 Product Demo
![Page 3: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/3.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.3
The Company
13,000,000 Producer Lifecycle Mgmt transactions
20,0000 customers use Vertafore
1,000 agencies adopted AMS360 in 2012
96 of the top 100 agencies use Vertafore
80 of the top 100 carriers use Vertafore
44 years transforming insurance
#1 software supplier to independent insurance
50,000,000 real-time transactions
![Page 4: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/4.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.4
Vertafore Solution Suite
Connectivity
4© 2013 Vertafore, Inc. and its subsidiaries.
Agency Carrier MGA/WholesalerContent and BusinessProcess Management
Content and BusinessProcess Management
Business IntelligenceBusiness Intelligence
Agency Management,Download and Real-timeDownload and Real-time
Policy IssuancePolicy Issuance
Producer LifecycleManagement
Producer LifecycleManagement
Producer LifecycleManagement
Comparative Rating Rating ManagementRating Interfaces
Reference Libraries Reference LibrariesReference Libraries
Producer Tools Producer ToolsProducer Tools
Content and BusinessProcess Management
Business Intelligence
Agency Management,Download and Real-time
Benefits Management
Connectivity
![Page 5: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/5.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.5
Breaking the Mold
• Need solutions to be re-usable
• Breaking the traditional SQL solution development pattern
• Freedom to choose the right technology to solve the problem
![Page 6: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/6.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.6
Design Goals
• Simple and Easy to User API
• Performance and Scalability
• Need to support both pull and push
![Page 7: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/7.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.7
Design Decisions
• “RESTful” web service using OData
• MongoDB for database
• RabbitMQ for queue to support mobile push
![Page 8: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/8.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.8
Why MongoDB?
• Performance and scalability
• No object to relational model translation
• Object model can be very flexible
• Supports all major platforms
• Excellent .NET and LINQ support
![Page 9: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/9.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.9
Overall Architecture
![Page 10: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/10.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.10
Object Model – NotificationMessage
• Type – admin, user, …• Priority – normal, critical, …• Author• Publisher• Recipient…
![Page 11: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/11.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.11
Object Model – UML Diagram
![Page 12: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/12.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.12
MongoDB Document – NotificationMessage
![Page 13: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/13.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.13
Message Service – Layered Diagram
![Page 14: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/14.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.14
public class NotificationMessagesController : ODataController { public IQueryable<NotificationMessage> Get(ODataQueryOptions<NotificationMessage> query); public async Task<NotificationMessage> Get([FromODataUri] string key); public async Task<IHttpActionResult> Post([FromBody] NotificationMessage message); public async Task<IHttpActionResult> Put([FromODataUri] string key, NotificationMessage entity); public async Task<IHttpActionResult> Patch([FromODataUri] string key, Delta<NotificationMessage> patch); }
Odata Layer - Controller
![Page 15: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/15.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.15
Domain Layer – Domain Services
![Page 16: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/16.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.16
public interface IRepository<T, U> { T Get(Expression<Func<T, U>> keyExpression, U key); IQueryable<T> Get();
T Create(T entity); T Update(T entity); bool Delete(T entity); }
Data Layer - Interface
![Page 17: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/17.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.17
public MongoRepository(MongoDatabase database, string collection) { Collection = database.GetCollection<T>(collection); } public T Get(Expression<Func<T, U>> exp, U key) { return Collection.FindOne(Query<T>.EQ(exp, key)); }
public IQueryable<T> Get() { return Collection.AsQueryable(); }
Data Layer - Implementation
![Page 18: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/18.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.18
private void InitializeStructureMap(IQueryRules rules) {DomainStructureMap.Map(container, (ConfigurationSection)ConfigurationManager.GetSection("NotificationCreatedEventQueue")); DataStructureMap.Map(container, ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString); });}
How Are The Three Layers Linked?
![Page 19: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/19.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.19
public static void Map(IRegistry container, ConfigurationSection notificationConfigurationSection) {container.For<IEntityEventProcessor>() .HybridHttpOrThreadLocalScoped() .Use<EntityEventProcessor>();
container.For<IDomainService<NotificationMessage, string>>() .HybridHttpOrThreadLocalScoped() .Use<NotificationMessageService>();}
Structure Map – Domain
![Page 20: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/20.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.20
public static void Map(IRegistry container, string dataConnection) { RegisterMappings(); container.For<IRepository<NotificationMessage, string>>() .HybridHttpOrThreadLocalScoped() .Use(r => new MongoRepository<NotificationMessage, string>(r.GetInstance<MongoDatabase>(), "Messages"));
container.For<IRepository<MessageHistory, string>>() .HybridHttpOrThreadLocalScoped() .Use(r => new MongoRepository<MessageHistory, string>(r.GetInstance<MongoDatabase>(), "MessageHistory")); }
Structure Map – Data
![Page 21: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/21.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.21
BsonClassMap.RegisterClassMap<NotificationMessage>(map => { map.AutoMap(); map.SetDiscriminator("NotificationMessage"); map.IdMemberMap.SetIdGenerator (StringObjectIdGenerator.Instance); });
BsonClassMap.RegisterClassMap<UserRecipient>(map => {
map.AutoMap(); map.SetDiscriminator("MessageRecipient_User");
}); // Other mappings omitted for clarity
Bson Class Map
![Page 22: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/22.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.22
MongoDB Replica Set
![Page 23: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/23.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.23
NotificationMessages.OrderByDescending (nm => nm.CreatedAt).Skip(100).Take(50);
NotificationMessages.Where(n => n.Id == "54132e3bf11fbc138c8f7448");NotificationMessages.Where (nm =>
nm.UserRecipients.Any(ur => ur.UserId == "35630")).OrderByDescending (nm => nm.CreatedAt).Take(10);
NotificationMessages.Where(x => x.Summary.Contains("New opportunity")).Take(10);
Usage Examples – Linq Queries
![Page 24: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/24.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.24
https://ServiceEndpoint/NotificationMessages()?$orderby=CreatedAt desc&$skip=100&$top=50
https://ServiceEndpoint/NotificationMessages('54132e3bf11fbc138c8f7448')
https://ServiceEndpoint/NotificationMessages()?$filter=UserRecipients/any(ur:ur/UserId eq '35630')&$orderby=CreatedAt desc&$top=10
https://ServiceEndpoint/NotificationMessages()?$filter=substringof('New opportunity',Summary)&$top=10
Usage Examples – Odata Queries
![Page 25: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/25.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.25
"op" : "query",
"ns" : "NotificationService.Messages",
"query" : {
"$query" : {
"UserRecipients" : {
"$elemMatch" : {
"UserId" : "35630"
}
} },
"$orderby" : {
"CreatedAt" : -1 }
},
Usage Examples – MongoDB Queries
![Page 26: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/26.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.26
Mobile Push Service
• Mobile device registration service– Register mobile device– Odata web service– Registration stored in MongoDB
• Windows service – Monitor queue message– Send message that has mobile destination to
Apple or Google for actual delivery
![Page 27: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/27.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.27
{ "_id" : "54174aad92d00721d4ef7315", "DeviceType" : "Android", "Token" : "<Device token goes here>", "AppId" : "SeattleDemo", "VssoId" : "35689", "VendorId" : "PipelineManager - Agent", "CreatedDt" : ISODate("2014-09-15T20:23:08.747Z"), "ModifiedDt" : ISODate("2014-09-15T20:23:08.747Z"), "DeviceData" : { "Data" : null }}
Device Registration – MongoDB Document
![Page 28: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/28.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.28
Mobile Push Service - Workflow
![Page 29: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/29.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.29
Overall Dev Experience
• What we liked– Very easy to setup– Great documentation and online resources– Great community support– No more mismatch of object to relational– Quick development cycle– Flexible schema works well
![Page 30: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/30.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.30
Overall Dev Experience
• Things that could have been better– 2.6 release felt to be rushed out. – No out of box encryption support– No MongoDB Management Service (MMS) on
windows
![Page 31: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/31.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.31
Operations Experience
• Hosting team was able to ramp up quickly
• Simple installation
• Quick and intuitive deployment of packages
• Easy to scale out
![Page 32: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/32.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.32
Push Notification Demo
![Page 33: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/33.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.33
Questions
![Page 34: Building a Common Message Solution with MongoDB at Vertafore](https://reader033.vdocument.in/reader033/viewer/2022061110/5453d105af795959498b618e/html5/thumbnails/34.jpg)
© 2014 Vertafore, Inc. and its subsidiaries.34