Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amqp: reusable connections #34

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Amqp: reusable connections #34

wants to merge 1 commit into from

Conversation

bobanco
Copy link
Contributor

@bobanco bobanco commented Apr 11, 2018

  • Add AMQP cached connection
  • Add tests


[Fact]
public void
The_AMQP_default_connection_providers_should_create_new_a_new_connection_per_invocation_of_LocalAmqpConnection()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"new_a_new" typo.

{

}
public static AmqpLocalConnectionProvider Instance=> new AmqpLocalConnectionProvider();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to create a new instance on every property invocation? It seems it can be cached in a static field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could omit the property itself and use a static field, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.


}
public static AmqpLocalConnectionProvider Instance=> new AmqpLocalConnectionProvider();
public override IConnection Get() => new ConnectionFactory().CreateConnection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, could ConnectionFactory be cached?

{
public class AmqpConnectionProvidersTest : Akka.TestKit.Xunit2.TestKit
{
private readonly ActorMaterializer _mat;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_mat is not used anywhere.

new AmqpDetailsConnectionProvider(new List<(string host, int port)> { (host, port) });

public AmqpDetailsConnectionProvider WithHostsAndPorts((string host, int port) hostAndPort,
params (string host, int port)[] hostAndPortList)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why such a strange signature? Would the following work?

public AmqpDetailsConnectionProvider WithHostsAndPorts(params (string host, int port)[] hostAndPortList)

public override string ToString()
{
return
$"AmqpDetailsConnectionProvider(HostAndPortList=({HostAndPortList.Select(x => $"[{x.host}:{x.port}]").Aggregate((left, right) => $"{right}, {left}")}), Credentials={Credentials}, VirtualHost={VirtualHost})";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit hard to see what Aggregate does here. What about more common string.Join?

$"AmqpDetailsConnectionProvider(HostAndPortList=({string.Join(", ", HostAndPortList.Select(x => $"[{x.host}:{x.port}]"))}), Credentials={Credentials}, VirtualHost={VirtualHost})";


public IReadOnlyList<(string host, int port)> HostAndPortList => _hostAndPortList.Any()
? _hostAndPortList.ToList()
: new List<(string host, int port)> {(_factory.HostName, _factory.Port)};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can be simplified:

public IReadOnlyList<(string host, int port)> HostAndPortList => _hostAndPortList.Any()
            ? _hostAndPortList
            : new [] {(_factory.HostName, _factory.Port)};

params (string host, int port)[] hostAndPortList)
{
return new AmqpConnectionFactoryConnectionProvider(_factory,
new List<(string host, int port)>(hostAndPortList.ToList()) {hostAndPort});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove .ToList()


public sealed class AmqpCachedConnectionProvider : AmqpConnectionProvider
{
private AtomicReference<IState> _state = new AtomicReference<IState>(Empty.Instance);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be made readonly.

}
public override IConnection Get()
{
var factory = new ConnectionFactory();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure it's ok to create a ConnectionFactory every time Get is called?

@Aaronontheweb
Copy link
Member

@bobanco still working on this?

@Aaronontheweb
Copy link
Member

@Arkatufus is this PR still necessary?

@Arkatufus
Copy link
Contributor

It looks promising, but the original fork is gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants