EventStore - issues integrating with protobuf-net - cqrs

I was looking at using EventStore with SQL Server for the data storage. Most of the performance hit is with SQL Server actually storing the data, and there is a lot of memory allocated in the web server as well.
It turns out it all boils down to the Serialization of the headers (from CommonDomain's EventStoreRepository class) and of the EventMessage (from EventStore).
So I tried to switch from the Binary Serializer to the Protobuf-net one. But the types that need serialization do not have the required attributes to be properly serialized.
Is it possible to use protobuf-net with EventStore + CommonDomain? Has anyone done it?

Related

Java Rest Client consuming JSON - how to create JAXB objects?

I need to write a rest client (in Java - using RestEasy) that can consume JSON responses. Regarding the need for the rest client (or wrapping service) to translate the JSON responses to a Java type, I see the following options:
1. map the response to a string and then use JsonParser tools to extract data and build types manually.
2. Use JAXB annotated POJOs - in conjunction with jackson - to automatically bind the json response to an object.
Regarding 2, is it desirable / correct to define an XSD to generate the JAXB annotated POJOs? I can advantages to doing this using, e.g. reuse by an XML client.
Thanks.
I'm a fan of #2.
The reasoning is that your JAXB annotated model objects essentially are the contract for the business/domain logic that you're trying to represent on a transport level, and POJOs obviously give you excellent control over getter/setter validation, and you can control your element names and namespaces with fine granularity.
With that said, I like having an additional "inner" model of POJOs (if necessary, depending on problem complexity/project scope) to isolate the transport layer from the domain objects. Also, you get a nice warm feeling that you're not directly tied to your transport layer if things need to change internally in your business/domain object representation. A co-worker mentioned Dozer, a tool for mapping beans to beans, but I have no direct experience with it to comment further.
I'm not a fan of generating code from XSDs. Often the code is ugly or downright unreadable; and managing change, however subtle or insignificant can introduce unexpected results. Maybe I'm wrong about that but I require good unit-tests on a proven model.
This is based on my personal experience writing a customer-facing SDK with a hairy XML-over-HTTP (we don't call it REST) API. JAXB/Jackson annotated POJOs made it relatively painless. Hope that helps.

.NET Session State Caching with Redis, MongoDB, ServiceStack

I have been doing some research on whether it is ok or not to cache .NET Session State in external Dbs such as Redis, MongoDb, or other highly scalable tools.
The output of my research was that even though MongoDB has more integration to do this kind of things, it seems that Redis is far more performant and has way more options (key expiration, sets, etc) to use.
There is this other framework called ServiceStack which has an implementation of a RedisClient but IMHO the way it is implemented is far more coupled than I would like to.
public override object OnGet(CachedOrders request)
{
var cacheKey = "some_unique_key_for_order";
return base.RequestContext.ToOptimizedResultUsingCache(this.CacheClient, cacheKey, () =>
{
//This delegate will be executed if the cache doesn't have an item
//with the provided key
//Return here your response DTO
//It will be cached automatically
});
}
So after this research, I would like to know your opinion and whether you have implemented this kind of caching in any of your apps. Can you please share you experiences?
Thanks!
ServiceStack's caching isn't coupled, the ToOptimizedResultUsingCache() method is just a convenience Extension method allowing you implement a common caching pattern in the minimal boilerplate necessary. The ToOptimizedResult method returns the most optimized result based on the MimeType and CompressionType from the IRequestContext. e.g. in a JSON service it would normally be the deflate'd output of the JSON Response DTO.
You don't have to use the extension method and can access the ICacheClient API directly as it's an auto-wired property in the ServiceBase class. If you require more functionality than the ICacheClient API can provide, I recommend using Redis and ServiceStack's C# RedisClient which gives you fast, atomic access to distributed comp-sci collections.
The benefit of using an ICacheClient API is that it's a testable implementation agnostic caching interface that currently has InMemory, Redis and Memcached providers.
I wrote a NuGet package for this 2 years ago, and we've been using it in production since then. It overrides the .NET SessionStateProvider with a custom class that allows persistence to Redis, with various features like:
Only write to Redis on values changing
Concurrent session access from multiple requests with the same session ID
Ability to access the session from Web API (although doing so violates REST principles, if you care)
Easy customization of serialization format (roll your own or change Json structure)
You can get it here: https://www.nuget.org/packages/RedisSessionProvider
Docs: https://github.com/welegan/RedisSessionProvider

Using RPC serialization/deserialization mechanism built in GWT

I am developing GWT offline application using HTML5 Local Storage. I would like to cache/store the transfer objects using com.google.gwt.storage.client.Storage (introduced in version 2.3). But the problem is that as for now (version 2.3) the Storage can only save the string values.
Is there any possibility to use GWT's built in rpc serialization/deseralization mechanism from client side code? So that I will be able to serialize transfer objects and store them in Local Storage and retrieve them when needed and deserialize the content.
GWT Docs have this to say:
Local Storage is String Storage
HTML5 local storage saves data in
string form as key-value pairs. If the data you wish to save is not
string data, you are responsible for conversion to and from string
when using LocalStorage. For proxy classes used with the GWT
RequestFactory, you can use RequestFactory#getSerializer() to do
string serializing. For non-proxy objects, you could use JSON
stringify and parse.
EDIT:
RequestFactory#getSerializer() returns an implementation of ProxySerializer. But
ProxySerializer Serializes graphs of EntityProxy objects. A
ProxySerializer is associated with an instance of a ProxyStore when it
is created via RequestFactory.getSerializer(ProxyStore).
So you cannot use it to serialize arbitrary objects. Only EntityProxy objects can be serialized this way. GWT documentation does not mention any method for doing such serialization for non-EntityProxy objects, so I think it is safe to assume that there is no ready-made solution for doing this so far. For non-EntityProxy objects, GWT docs (quoted above) recommend using JSON serialization.

How to use Entity Framework 4.0 with Xml or in-memory Storage (non-SQL)

How do I specify Xml or just in-memory storge for Entity Framework models? The connection string requires a provider (usually a SQL provider string). But it won't let me omit the provider.
I realize I could completely throw away the designer generated objects and go pure POCO, but then I'd have to implement my own serialization layer (could do that, but it's overkill for the tiny project I'm working on).
Is there built-in support in EF 4.0 for this that I'm missing or do I just need to go the pure POCO route and discard the designer experience entirely :(
If you want to store data in Xml or memory you should probably not use EF. EF is designed to work with relational databases.
See also: Entity Framework with XML Files
For storing data in memory use System.Runtime.Caching
For storing data in xml files see: http://msdotnetsupport.blogspot.com/2007/04/reading-and-writing-xml-files-using-c.html
This is a good way to do what you're probably thinking.
Use a SQLite db as the backing store. That way you get you're single local file and you can still use almost all of EF.
http://dotnet.dzone.com/news/sqlite-entity-framework-4

Sending persisted JDO instances over GWT-RPC

I've just started learning Google Web Toolkit and finished writing the Stock Watcher tutorial app.
Is my thinking correct that if one wants to persist a business object (like a Stock) using JDO and send it back and forth to/from the client over RPC then one has to create two separate classes for that object: One with the JDO annotations for persisting it on the server and another which is serialisable and used over RPC?
I notice the Stock Watcher has separate classes and I can theorise why:
Otherwise the gwt compiler would try
to generate javascript for everything
the persisted class referenced like
JDO and com.google.blah.users.User, etc
Also there may be logic on the server-side
class which doesn't apply to the client
and vice-versa.
I just want to make sure I'm understanding this correctly. I don't want to have to create two versions of all my business object classes which I want to use over RPC if I don't have to.
The short answer is: you don't need to create duplicate classes.
I recommend that you take a look from the following google groups discussion on the gwt-contributors list:
http://groups.google.com/group/google-web-toolkit-contributors/browse_thread/thread/3c768d8d33bfb1dc/5a38aa812c0ac52b
Here is an interesting excerpt:
If this is all you're interested in, I
described a way to make GAE and
GWT-RPC work together "out of the
box". Just declare your entities as:
#PersistenceCapable(identityType =
IdentityType.APPLICATION, detachable
= "false") public class MyPojo implements Serializable { }
and everything will work, but you'll
have to manually deal with
re-attachment when sending objects
from the client back to the server.
You can use this option, and you will not need a mirror (DTO) class.
You can also try gilead (former hibernate4gwt), which takes care of some details within the problems of serializing enhanced objects.
Your assessment is correct. JDO replaces instances of Collections with their own implementations, in order to sniff when the object graph changes, I suppose. These implementations are not known by the GWT compiler, so it will not be able to serialize them. This happens often for classes that are composed of otherwise GWT compliant types, but with JDO annotations, especially if some of the object properties are Collections.
For a detailed explanation and a workaround, check out this pretty influential essay on the topic: http://timepedia.blogspot.com/2009/04/google-appengine-and-gwt-now-marriage.html
I finally found a solution. Don't change your object at all, but for the listing do it this way:
List<YourCustomObject> secureList=(List<YourCustomObject>)pm.newQuery(query).execute();
return new ArrayList<YourCustomObject>(secureList);
The actual problem is not in Serializing the Object... the problem is to Serialize the Collection class which is implemented by Google and is not allowed to Serialize out.
You do not have to create two versions of the domain model.
Here are two tips:
Use a String encoded key, not the Appengine Key class.
pojo = pm.detachCopy(pojo)
...will remove all the JDO enhancements.
You don't have to create separate instances at all, in fact you're better off not doing it. Your JDO objects should be plain POJOs anyway, and should never contain business logic. That's for your business layer, not your persistent objects themselves.
All you need to do is include the source for the annotations you are using and GWT should compile your class just fine. Also, you want to avoid using libraries that GWT can't compile (like things that use reflection, etc.), but in all the projects I've done this has never been a problem.
I think that a better format to send objects through GWT is through JSON. In this case from the server a JSON string would be sent which would then have to be parsed in the client. The advantage is that the final Javascript which is rendered in the browser has a smaller size. thus causing the page to load faster.
Secondly to send objects through GWT, the objects should be serializable. This may not be the case for all objects
Thirdly GWT has inbuilt functions to handle JSON... so no issues on the client end