NSaga icon indicating copy to clipboard operation
NSaga copied to clipboard

Working sample for MySQL

Open trailmax opened this issue 7 years ago • 14 comments

trailmax avatar Jan 22 '17 00:01 trailmax

Hi tailmax.

How soon can you get it working with MySql? I would very much like to use this, but can't, because it's dependent soley on SqlServer. Please respond asap, if possible.

Iulian94 avatar Aug 14 '18 12:08 Iulian94

@Iulian94 I had no immediate plans of using MySql, as I don't use it anywhere.

However currently provided SqlRepository can work with MySql. It will be a matter of providing correclty formed connection string (See PetaPoco documentation for that).

However I sense there will be an issue in creating an initial schema for the tables, as SQL I used worked in SQL Server and I never tested it in MySql. But you can try an report back if there is an issue.

trailmax avatar Aug 14 '18 12:08 trailmax

@trailmax Thanks a lot for the quick response!

I've tried it, and it does not work. It gives me an error that it can not login when Consuming the first message. This is the stack trace, while I'm using a connection string format PetaPoco provides: "server=localhost;UId=test;Pwd=test;database=test"

I've downloaded the binaries, will try to figure out what is wrong and come back to you.

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at NSaga.NSagaReflection.InvokeGenericMethod(Object invocationTarget, String methodName, Type genericParameterType, Object[] parameters) in C:\projects\nsaga\src\NSaga\NSagaReflection.cs:line 140 at NSaga.SagaMediator.Consume(IInitiatingSagaMessage initiatingMessage) in C:\projects\nsaga\src\NSaga\SagaMediator.cs:line 52 at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.Open() at NSaga.ConnectionFactory.CreateOpenConnection() in C:\projects\nsaga\src\NSaga\SqlServer\IConnectionFactory.cs:line 46 at NSaga.SqlSagaRepository.Find[TSaga](Guid correlationId) in C:\projects\nsaga\src\NSaga\SqlServer\SqlSagaRepository.cs:line 61

Iulian94 avatar Aug 14 '18 13:08 Iulian94

@Iulian94 What is the actual message of the exception? How does your connection string look like?

trailmax avatar Aug 14 '18 13:08 trailmax

@trailmax Sorry for the late answer.. I've resolved that, it was because of some "charset" setting the connectionstring contained + I didn't use the override of the IConnectionFactory correctly. I now have the following code:

container.Register<IConnectionFactory>(() => new NSagaMySqlProvider(connectionStringName), Lifestyle.Singleton);

container.RegisterNSagaComponents()
.UseSagaRepository<SqlSagaRepository>();

which works.

Small problem though.. MySql doesn't have the notion of Schemas, ergo, it crashes. I resolved this by taking the binaries and changing the const properties, but, it's not ok, as I'm not using the Nuget anymore. Can we find a way around this? I searched but couldn't without maybe implementing the whole SqlSagaRepository myself + replacing through the sql queries manually or creating MySqlSagaData and MySqlSagaHeaders (for the sole purpose of editing that small detail, aka table name).

Iulian94 avatar Aug 14 '18 15:08 Iulian94

@Iulian94 problem with renaming tables - it'll break all the existing solutions for people who are already using this package. Including my solutions.

So it'll have to be a separate implementation of the repository and other DB-related structure for MySql.

Since you already have the code working, would you like to share it via a Pull Request?

trailmax avatar Aug 14 '18 21:08 trailmax

@trailmax I've made the pull request https://github.com/AMVSoftware/NSaga/pull/37. Please review it and push to nuget if it's all ok. I've tested it and it works like this, without any additional IConnectionFactories (it's all included into the NSaga solution), or adding a complete new SagaRepository (for just a few lines):

container.RegisterNSagaComponents()
                    .UseSagaRepository<SqlSagaRepository>()
                    .UseMySql()
                    .WithConnectionStringName("local_db_name");

The only problem that I had is that SagaData is internal and I can't inject the IQueryWrapper, because the constructor in public. Tried creating a different internal constructor for this, but as I don't know the ramifications for the DI, it would be best for you to do it, if necessary.

Iulian94 avatar Aug 15 '18 12:08 Iulian94

@trailmax Can you please tell me whether it would be possible to carry this out until tomorrow, and fast forward the deployment of the package? Thanks in anticipation.

Iulian94 avatar Aug 15 '18 15:08 Iulian94

@Iulian94 I'm snowed under by requests for work in paid projects. And that unfortunately takes priority. So unlikely there will be a relese for tomorrow.

trailmax avatar Aug 15 '18 16:08 trailmax

@trailmax Ok, thanks.. I don't think it will take you more than 30 minutes to test it out with a previous application to see it still works, approve and deploy it, as there weren't that many changes, so, please have a look, when you've got the time. This is also for a paid project for which I have a deadline until Friday evening and would like to get over with. Sorry if I am being a bit pushy with this. Cool project, btw :)

Iulian94 avatar Aug 15 '18 16:08 Iulian94

@Iulian94 OK, you are setting my priorities, giving me a deadline and you are getting paid for your project. Should I ask to be paid for my time as well?

trailmax avatar Aug 15 '18 19:08 trailmax

@trailmax I didn't mean it that way.. I just wanted to let you know that I also have a time limit on this, and that's why I was trying to push it that hard. Sorry if I was stressing you out so much with this.

Iulian94 avatar Aug 15 '18 21:08 Iulian94

@trailmax Thanks for doing the code review for the pull request. I will do another pull request with only the minimal changes that are needed for it to work with MySql and nothing more.

Iulian94 avatar Aug 16 '18 00:08 Iulian94

@trailmax I've added the last pull request https://github.com/AMVSoftware/NSaga/pull/38. It's the most simplified version I could go with. In case this still doesn't cut it, I will do another pull request with the duplicated SqlSagaRepository with just the table objects as differences, or implement the MySqlSagaRepository myself as a package user, like you said, and that's it.

Iulian94 avatar Aug 16 '18 01:08 Iulian94