Re: [nhusers] Nhibernate async await

2020-10-30 Thread Hakan karaoğlu
Hi,
Firstly, thank you so much for reply 
My project's Nhibernate configuration is as follows. Is there anything 
wrong here, is there a point I'm missing?

public static IServiceCollection AddSniffactorNhibernate(this 
IServiceCollection services, string connectionString)
{
Check.NotNull(connectionString);

ISessionFactory _sessionFactory = 
BuildSessionFactory(connectionString);

services.AddSingleton(_sessionFactory);
services.AddScoped(factory => 
factory.GetServices().First().OpenSession());
services.AddScoped(typeof(IRepository<>), 
typeof(NhRepositoryBase<>));
services.AddSingleton(typeof(IUnitOfWork), 
typeof(NhUnitOfWork));

ConsoleHelper.WriteWarningCommandLine(">>> NHibernate 
Configurasyonu tamamlandı.");

return services;
}

private static ISessionFactory BuildSessionFactory(string 
connectionString)
{
FluentConfiguration configuration = Fluently.Configure()

.Database(OracleManagedDataClientConfiguration.Oracle9.ConnectionString(connectionString))
.Mappings(m => m.FluentMappings
.AddFromAssemblyOf()
.Conventions.Add(
ConventionBuilder.Property.When(criteria => 
criteria.Expect(x => x.Nullable, Is.Not.Set), x => x.Not.Nullable()))
.Conventions.Add()
);

return configuration.BuildSessionFactory();
}

private class OtherConversions : IHasManyConvention, IReferenceConvention
{
public void Apply(IOneToManyCollectionInstance instance)
{
instance.LazyLoad();
instance.AsBag();
instance.Cascade.SaveUpdate();
instance.Inverse();
}

public void Apply(IManyToOneInstance instance)
{
instance.LazyLoad(Laziness.Proxy);
instance.Cascade.None();
instance.Not.Nullable();
}
}
30 Ekim 2020 Cuma tarihinde saat 22:57:18 UTC+3 itibarıyla Quicoli şunları 
yazdı:

> Hi
>
> Open and close a session inside your for each loop and you will be fine
>
> On Fri, Oct 30, 2020, 17:46 Hakan karaoğlu  wrote:
>
>> Hi,
>>
>> I'm using rabbitmq and nhibernate in a .net core project. I run 
>> asynchronous queries for database operations on some consumers. For 
>> example, I am sending a single message to the queue, the message is 
>> processed successfully, but when I send 100 messages, database operations 
>> start getting errors after a while.
>>
>> I tested the similar structure as follows. I did database transactions 
>> 100 times in a loop and it didn't give an error. But when I tried it in 
>> parallel loop, it gave an error like in rabbitmq.
>>
>> Is this from Nhibernate or is there a different logic? Nhibernate not 
>> thread-safe?
>>
>> Sample Code with Error :
>>
>> Parallel.For(0, 100, async act =>
>> {
>> var ws = await 
>> _workspaceRepository.GetWorkspaceByIdAsync(66);
>> System.Console.WriteLine($"GetWorkspaceByIdAsync : 
>> {ws.Name}");
>> var keywords = await 
>> _workspaceKeywordRepository.GetForbiddenKeywordsByWorkspaceAsync(66);
>> 
>> System.Console.WriteLine($"GetForbiddenKeywordsByWorkspaceAsync : 
>> {keywords.Count}");
>> var IsforbiddenKeyword = await 
>> HasForbiddenKeywordAsync(66, "facebook", "instagram");
>> System.Console.WriteLine($"HasForbiddenKeywordAsync : 
>> {IsforbiddenKeyword}");
>> });
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "nhusers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to nhusers+u...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/nhusers/15a15084-855f-4d1c-9ebd-ea1b62cf9a0cn%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nhusers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nhusers/7024ae71-4300-48f5-b5f7-23c3e35b2c1en%40googlegroups.com.


Re: [nhusers] Nhibernate async await

2020-10-30 Thread Hakan karaoğlu
The parallel loop is just one example. I am using the methods called here 
within a rabbitmq consumer.

For Example:

public async Task Consume(ConsumeContext 
context)
{
var wsMessage = context.Message;
try
{
var feedDispatcher = 
FeedDispatcherFactory.CreateDispatcher(wsMessage.FeedProxy, 
wsMessage.Keywords);   
var workspaceAsync = await 
feedDispatcher.GetWorkspaceAsync(wsMessage.FeedProxy, wsMessage.Keywords);  
  

foreach (var workspaceId in workspaceAsync.Keys)
{
var sentimentDetectionMessage = new 
SentimentDetectionMessage
{
ConversationId = wsMessage.ConversationId,
FeedProxy = wsMessage.FeedProxy,
FeederProxy = wsMessage.FeederProxy,
Keywords = workspaceAsync[workspaceId],
WorkspaceId = workspaceId
};
await _bus.Publish(sentimentDetectionMessage);
}
}
catch (Exception exp)
{
throw exp;
}
}

30 Ekim 2020 Cuma tarihinde saat 23:04:11 UTC+3 itibarıyla Gunnar Liljas 
şunları yazdı:

> You really shouldn't combine Parallel.For and async. Ever. And 
> NHibernate's session isn't thread safe, so it shouldn't be used from 
> multiple threads.
>
> /G
>
> On Fri, Oct 30, 2020 at 6:46 PM Hakan karaoğlu  
> wrote:
>
>> Hi,
>>
>> I'm using rabbitmq and nhibernate in a .net core project. I run 
>> asynchronous queries for database operations on some consumers. For 
>> example, I am sending a single message to the queue, the message is 
>> processed successfully, but when I send 100 messages, database operations 
>> start getting errors after a while.
>>
>> I tested the similar structure as follows. I did database transactions 
>> 100 times in a loop and it didn't give an error. But when I tried it in 
>> parallel loop, it gave an error like in rabbitmq.
>>
>> Is this from Nhibernate or is there a different logic? Nhibernate not 
>> thread-safe?
>>
>> Sample Code with Error :
>>
>> Parallel.For(0, 100, async act =>
>> {
>> var ws = await 
>> _workspaceRepository.GetWorkspaceByIdAsync(66);
>> System.Console.WriteLine($"GetWorkspaceByIdAsync : 
>> {ws.Name}");
>> var keywords = await 
>> _workspaceKeywordRepository.GetForbiddenKeywordsByWorkspaceAsync(66);
>> 
>> System.Console.WriteLine($"GetForbiddenKeywordsByWorkspaceAsync : 
>> {keywords.Count}");
>> var IsforbiddenKeyword = await 
>> HasForbiddenKeywordAsync(66, "facebook", "instagram");
>> System.Console.WriteLine($"HasForbiddenKeywordAsync : 
>> {IsforbiddenKeyword}");
>> });
>>
>> -- 
>>
> You received this message because you are subscribed to the Google Groups 
>> "nhusers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to nhusers+u...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/nhusers/15a15084-855f-4d1c-9ebd-ea1b62cf9a0cn%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nhusers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nhusers/4d245421-bf91-474d-97eb-f730e083028fn%40googlegroups.com.


Re: [nhusers] Nhibernate async await

2020-10-30 Thread Gunnar Liljas
You really shouldn't combine Parallel.For and async. Ever. And
NHibernate's session isn't thread safe, so it shouldn't be used from
multiple threads.

/G

On Fri, Oct 30, 2020 at 6:46 PM Hakan karaoğlu 
wrote:

> Hi,
>
> I'm using rabbitmq and nhibernate in a .net core project. I run
> asynchronous queries for database operations on some consumers. For
> example, I am sending a single message to the queue, the message is
> processed successfully, but when I send 100 messages, database operations
> start getting errors after a while.
>
> I tested the similar structure as follows. I did database transactions 100
> times in a loop and it didn't give an error. But when I tried it in
> parallel loop, it gave an error like in rabbitmq.
>
> Is this from Nhibernate or is there a different logic? Nhibernate not
> thread-safe?
>
> Sample Code with Error :
>
> Parallel.For(0, 100, async act =>
> {
> var ws = await
> _workspaceRepository.GetWorkspaceByIdAsync(66);
> System.Console.WriteLine($"GetWorkspaceByIdAsync :
> {ws.Name}");
> var keywords = await
> _workspaceKeywordRepository.GetForbiddenKeywordsByWorkspaceAsync(66);
>
> System.Console.WriteLine($"GetForbiddenKeywordsByWorkspaceAsync :
> {keywords.Count}");
> var IsforbiddenKeyword = await
> HasForbiddenKeywordAsync(66, "facebook", "instagram");
> System.Console.WriteLine($"HasForbiddenKeywordAsync :
> {IsforbiddenKeyword}");
> });
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nhusers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nhusers/15a15084-855f-4d1c-9ebd-ea1b62cf9a0cn%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nhusers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nhusers/CAAOnFsPMiqskXZh3s2ETg67tZy%3DkNGwWTeO2iE-7ONEkY8LZpg%40mail.gmail.com.


Re: [nhusers] Nhibernate async await

2020-10-30 Thread Paulo Quicoli
Hi

Open and close a session inside your for each loop and you will be fine

On Fri, Oct 30, 2020, 17:46 Hakan karaoğlu  wrote:

> Hi,
>
> I'm using rabbitmq and nhibernate in a .net core project. I run
> asynchronous queries for database operations on some consumers. For
> example, I am sending a single message to the queue, the message is
> processed successfully, but when I send 100 messages, database operations
> start getting errors after a while.
>
> I tested the similar structure as follows. I did database transactions 100
> times in a loop and it didn't give an error. But when I tried it in
> parallel loop, it gave an error like in rabbitmq.
>
> Is this from Nhibernate or is there a different logic? Nhibernate not
> thread-safe?
>
> Sample Code with Error :
>
> Parallel.For(0, 100, async act =>
> {
> var ws = await
> _workspaceRepository.GetWorkspaceByIdAsync(66);
> System.Console.WriteLine($"GetWorkspaceByIdAsync :
> {ws.Name}");
> var keywords = await
> _workspaceKeywordRepository.GetForbiddenKeywordsByWorkspaceAsync(66);
>
> System.Console.WriteLine($"GetForbiddenKeywordsByWorkspaceAsync :
> {keywords.Count}");
> var IsforbiddenKeyword = await
> HasForbiddenKeywordAsync(66, "facebook", "instagram");
> System.Console.WriteLine($"HasForbiddenKeywordAsync :
> {IsforbiddenKeyword}");
> });
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nhusers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nhusers/15a15084-855f-4d1c-9ebd-ea1b62cf9a0cn%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nhusers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nhusers/CAF8vUGXXirEF3Pa6W58scKMLu_iU%2B7Z79Op6y%3DjTTxCwLO%2B%2BVw%40mail.gmail.com.


[nhusers] Nhibernate async await

2020-10-30 Thread Hakan karaoğlu
Hi,

I'm using rabbitmq and nhibernate in a .net core project. I run 
asynchronous queries for database operations on some consumers. For 
example, I am sending a single message to the queue, the message is 
processed successfully, but when I send 100 messages, database operations 
start getting errors after a while.

I tested the similar structure as follows. I did database transactions 100 
times in a loop and it didn't give an error. But when I tried it in 
parallel loop, it gave an error like in rabbitmq.

Is this from Nhibernate or is there a different logic? Nhibernate not 
thread-safe?

Sample Code with Error :

Parallel.For(0, 100, async act =>
{
var ws = await 
_workspaceRepository.GetWorkspaceByIdAsync(66);
System.Console.WriteLine($"GetWorkspaceByIdAsync : 
{ws.Name}");
var keywords = await 
_workspaceKeywordRepository.GetForbiddenKeywordsByWorkspaceAsync(66);

System.Console.WriteLine($"GetForbiddenKeywordsByWorkspaceAsync : 
{keywords.Count}");
var IsforbiddenKeyword = await HasForbiddenKeywordAsync(66, 
"facebook", "instagram");
System.Console.WriteLine($"HasForbiddenKeywordAsync : 
{IsforbiddenKeyword}");
});

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nhusers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nhusers/15a15084-855f-4d1c-9ebd-ea1b62cf9a0cn%40googlegroups.com.