@@ -159,7 +159,7 @@ public class ConnectionFactory implements Cloneable {
159159
160160 private boolean nio = false ;
161161 private boolean netty = false ;
162-
162+
163163 private FrameHandlerFactory frameHandlerFactory ;
164164 private final NettyConfiguration nettyConf = new NettyConfiguration (this );
165165 private NioParams nioParams = new NioParams ();
@@ -817,7 +817,8 @@ public boolean isSSL() {
817817 * instead.
818818 */
819819 public void useSslProtocol () throws NoSuchAlgorithmException , KeyManagementException {
820- useSslProtocol (computeDefaultTlsProtocol (
820+ useSslProtocol (
821+ computeDefaultTlsProtocol (
821822 SSLContext .getDefault ().getSupportedSSLParameters ().getProtocols ()));
822823 }
823824
@@ -835,7 +836,7 @@ public void useSslProtocol() throws NoSuchAlgorithmException, KeyManagementExcep
835836 *
836837 * <p>Note this method has NO effect when using Netty, use {@link
837838 * com.rabbitmq.client.ConnectionFactory.NettyConfiguration#sslContext(io.netty.handler.ssl.SslContext)}
838- * instead.
839+ * instead.
839840 *
840841 * @see #setSslContextFactory(SslContextFactory)
841842 */
@@ -1498,185 +1499,185 @@ public NettyConfiguration eventLoopGroup(EventLoopGroup eventLoopGroup) {
14981499 return this ;
14991500 }
15001501
1501- /**
1502- * An extension point to customize Netty's {@link io.netty.channel.Channel}s used for
1503- * connections.
1504- *
1505- * @param channelCustomizer the customization callback
1506- * @return this configuration instance
1507- */
1508- public NettyConfiguration channelCustomizer (
1509- Consumer <io .netty .channel .Channel > channelCustomizer ) {
1510- this .channelCustomizer = channelCustomizer ;
1511- return this ;
1512- }
1513-
1514- /**
1515- * An extension point to customize Netty's {@link Bootstrap}s used to configure connections.
1516- *
1517- * @param bootstrapCustomizer the bootstrap customization callback
1518- * @return this configuration instance
1519- */
1520- public NettyConfiguration bootstrapCustomizer (Consumer <Bootstrap > bootstrapCustomizer ) {
1521- this .bootstrapCustomizer = bootstrapCustomizer ;
1522- return this ;
1523- }
1524-
1525- /**
1526- * Netty {@link SslContext} for TLS connections.
1527- *
1528- * <p>Use {@link SslContextBuilder#forClient()} to configure and create an instance.
1529- *
1530- * @param sslContext the SSL context
1531- * @return this configuration instance
1532- */
1533- public NettyConfiguration sslContext (SslContext sslContext ) {
1534- this .sslContextFactory = name -> sslContext ;
1535- return this ;
1536- }
1537-
1538- /**
1539- * A factory to create {@link io.netty.handler.ssl.SslContext} depending on the connection name.
1540- *
1541- * @param sslContextFactory the factory
1542- * @return this configuration instance
1543- */
1544- public NettyConfiguration sslContextFactory (Function <String , SslContext > sslContextFactory ) {
1545- this .sslContextFactory = sslContextFactory ;
1546- return this ;
1547- }
1548-
1549- /**
1550- * Go back to the connection factory.
1551- *
1552- * @return the connection factory
1553- */
1554- public ConnectionFactory connectionFactory () {
1555- return this .cf ;
1556- }
1557-
1558- private boolean isTls () {
1559- return this .sslContextFactory != null ;
1560- }
1561- }
1562-
1563- public ConnectionParams params (ExecutorService consumerWorkServiceExecutor ) {
1564- ConnectionParams result = new ConnectionParams ();
1565-
1566- result .setCredentialsProvider (credentialsProvider );
1567- result .setConsumerWorkServiceExecutor (consumerWorkServiceExecutor );
1568- result .setVirtualHost (virtualHost );
1569- result .setClientProperties (getClientProperties ());
1570- result .setRequestedFrameMax (requestedFrameMax );
1571- result .setRequestedChannelMax (requestedChannelMax );
1572- result .setShutdownTimeout (shutdownTimeout );
1573- result .setSaslConfig (saslConfig );
1574- result .setNetworkRecoveryInterval (networkRecoveryInterval );
1575- result .setRecoveryDelayHandler (recoveryDelayHandler );
1576- result .setTopologyRecovery (topologyRecovery );
1577- result .setTopologyRecoveryExecutor (topologyRecoveryExecutor );
1578- result .setExceptionHandler (exceptionHandler );
1579- result .setThreadFactory (threadFactory );
1580- result .setHandshakeTimeout (handshakeTimeout );
1581- result .setRequestedHeartbeat (requestedHeartbeat );
1582- result .setShutdownExecutor (shutdownExecutor );
1583- result .setHeartbeatExecutor (heartbeatExecutor );
1584- result .setChannelRpcTimeout (channelRpcTimeout );
1585- result .setChannelShouldCheckRpcResponseType (channelShouldCheckRpcResponseType );
1586- result .setWorkPoolTimeout (workPoolTimeout );
1587- result .setErrorOnWriteListener (errorOnWriteListener );
1588- result .setTopologyRecoveryFilter (topologyRecoveryFilter );
1589- result .setConnectionRecoveryTriggeringCondition (connectionRecoveryTriggeringCondition );
1590- result .setTopologyRecoveryRetryHandler (topologyRecoveryRetryHandler );
1591- result .setRecoveredQueueNameSupplier (recoveredQueueNameSupplier );
1592- result .setTrafficListener (trafficListener );
1593- result .setCredentialsRefreshService (credentialsRefreshService );
1594- result .setMaxInboundMessageBodySize (maxInboundMessageBodySize );
1595- return result ;
1596- }
1597-
1598- protected AMQConnection createConnection (
1599- ConnectionParams params , FrameHandler frameHandler , MetricsCollector metricsCollector ) {
1600- return new AMQConnection (params , frameHandler , metricsCollector , observationCollector );
1502+ /**
1503+ * An extension point to customize Netty's {@link io.netty.channel.Channel}s used for
1504+ * connections.
1505+ *
1506+ * @param channelCustomizer the customization callback
1507+ * @return this configuration instance
1508+ */
1509+ public NettyConfiguration channelCustomizer (
1510+ Consumer <io .netty .channel .Channel > channelCustomizer ) {
1511+ this .channelCustomizer = channelCustomizer ;
1512+ return this ;
16011513 }
16021514
16031515 /**
1604- * Create a new broker connection .
1516+ * An extension point to customize Netty's {@link Bootstrap}s used to configure connections .
16051517 *
1606- * <p>If <a href="https://www.rabbitmq.com/api-guide.html#recovery">automatic connection
1607- * recovery</a> is enabled, the connection returned by this method will be {@link Recoverable}.
1608- * Reconnection attempts will always use the address configured on {@link ConnectionFactory}.
1609- *
1610- * @return an interface to the connection
1611- * @throws IOException if it encounters a problem
1518+ * @param bootstrapCustomizer the bootstrap customization callback
1519+ * @return this configuration instance
16121520 */
1613- public Connection newConnection () throws IOException , TimeoutException {
1614- return newConnection (
1615- this . sharedExecutor , Collections . singletonList ( new Address ( getHost (), getPort ()))) ;
1521+ public NettyConfiguration bootstrapCustomizer ( Consumer < Bootstrap > bootstrapCustomizer ) {
1522+ this . bootstrapCustomizer = bootstrapCustomizer ;
1523+ return this ;
16161524 }
16171525
16181526 /**
1619- * Create a new broker connection .
1527+ * Netty {@link SslContext} for TLS connections .
16201528 *
1621- * <p>If <a href="https://www.rabbitmq.com/api-guide.html#recovery">automatic connection
1622- * recovery</a> is enabled, the connection returned by this method will be {@link Recoverable}.
1623- * Reconnection attempts will always use the address configured on {@link ConnectionFactory}.
1529+ * <p>Use {@link SslContextBuilder#forClient()} to configure and create an instance.
16241530 *
1625- * @param connectionName client-provided connection name (an arbitrary string). Will be displayed
1626- * in management UI if the server supports it.
1627- * @return an interface to the connection
1628- * @throws IOException if it encounters a problem
1531+ * @param sslContext the SSL context
1532+ * @return this configuration instance
16291533 */
1630- public Connection newConnection (String connectionName ) throws IOException , TimeoutException {
1631- return newConnection (
1632- this .sharedExecutor ,
1633- Collections .singletonList (new Address (getHost (), getPort ())),
1634- connectionName );
1534+ public NettyConfiguration sslContext (SslContext sslContext ) {
1535+ this .sslContextFactory = name -> sslContext ;
1536+ return this ;
16351537 }
16361538
16371539 /**
1638- * Create a new broker connection.
1540+ * A factory to create {@link io.netty.handler.ssl.SslContext} depending on the connection name .
16391541 *
1640- * <p>If <a href="https://www.rabbitmq.com/api-guide.html#recovery">automatic connection
1641- * recovery</a> is enabled, the connection returned by this method will be {@link Recoverable}.
1642- * Reconnection attempts will always use the address configured on {@link ConnectionFactory}.
1643- *
1644- * @param executor thread execution service for consumers on the connection
1645- * @return an interface to the connection
1646- * @throws IOException if it encounters a problem
1542+ * @param sslContextFactory the factory
1543+ * @return this configuration instance
16471544 */
1648- public Connection newConnection (ExecutorService executor ) throws IOException , TimeoutException {
1649- return newConnection (executor , Collections .singletonList (new Address (getHost (), getPort ())));
1545+ public NettyConfiguration sslContextFactory (Function <String , SslContext > sslContextFactory ) {
1546+ this .sslContextFactory = sslContextFactory ;
1547+ return this ;
16501548 }
16511549
16521550 /**
1653- * Create a new broker connection.
1654- *
1655- * <p>If <a href="https://www.rabbitmq.com/api-guide.html#recovery">automatic connection
1656- * recovery</a> is enabled, the connection returned by this method will be {@link Recoverable}.
1657- * Reconnection attempts will always use the address configured on {@link ConnectionFactory}.
1551+ * Go back to the connection factory.
16581552 *
1659- * @param executor thread execution service for consumers on the connection
1660- * @param connectionName client-provided connection name (an arbitrary string). Will be displayed
1661- * in management UI if the server supports it.
1662- * @return an interface to the connection
1663- * @throws IOException if it encounters a problem
1553+ * @return the connection factory
16641554 */
1665- public Connection newConnection (ExecutorService executor , String connectionName )
1666- throws IOException , TimeoutException {
1667- return newConnection (
1668- executor , Collections .singletonList (new Address (getHost (), getPort ())), connectionName );
1555+ public ConnectionFactory connectionFactory () {
1556+ return this .cf ;
16691557 }
16701558
1671- protected AddressResolver createAddressResolver (List <Address > addresses ) {
1672- if (addresses == null || addresses .isEmpty ()) {
1673- throw new IllegalArgumentException ("Please provide at least one address to connect to" );
1674- } else if (addresses .size () > 1 ) {
1675- return new ListAddressResolver (addresses );
1676- } else {
1677- return new DnsRecordIpAddressResolver (addresses .get (0 ), isSSL ());
1678- }
1559+ private boolean isTls () {
1560+ return this .sslContextFactory != null ;
1561+ }
1562+ }
1563+
1564+ public ConnectionParams params (ExecutorService consumerWorkServiceExecutor ) {
1565+ ConnectionParams result = new ConnectionParams ();
1566+
1567+ result .setCredentialsProvider (credentialsProvider );
1568+ result .setConsumerWorkServiceExecutor (consumerWorkServiceExecutor );
1569+ result .setVirtualHost (virtualHost );
1570+ result .setClientProperties (getClientProperties ());
1571+ result .setRequestedFrameMax (requestedFrameMax );
1572+ result .setRequestedChannelMax (requestedChannelMax );
1573+ result .setShutdownTimeout (shutdownTimeout );
1574+ result .setSaslConfig (saslConfig );
1575+ result .setNetworkRecoveryInterval (networkRecoveryInterval );
1576+ result .setRecoveryDelayHandler (recoveryDelayHandler );
1577+ result .setTopologyRecovery (topologyRecovery );
1578+ result .setTopologyRecoveryExecutor (topologyRecoveryExecutor );
1579+ result .setExceptionHandler (exceptionHandler );
1580+ result .setThreadFactory (threadFactory );
1581+ result .setHandshakeTimeout (handshakeTimeout );
1582+ result .setRequestedHeartbeat (requestedHeartbeat );
1583+ result .setShutdownExecutor (shutdownExecutor );
1584+ result .setHeartbeatExecutor (heartbeatExecutor );
1585+ result .setChannelRpcTimeout (channelRpcTimeout );
1586+ result .setChannelShouldCheckRpcResponseType (channelShouldCheckRpcResponseType );
1587+ result .setWorkPoolTimeout (workPoolTimeout );
1588+ result .setErrorOnWriteListener (errorOnWriteListener );
1589+ result .setTopologyRecoveryFilter (topologyRecoveryFilter );
1590+ result .setConnectionRecoveryTriggeringCondition (connectionRecoveryTriggeringCondition );
1591+ result .setTopologyRecoveryRetryHandler (topologyRecoveryRetryHandler );
1592+ result .setRecoveredQueueNameSupplier (recoveredQueueNameSupplier );
1593+ result .setTrafficListener (trafficListener );
1594+ result .setCredentialsRefreshService (credentialsRefreshService );
1595+ result .setMaxInboundMessageBodySize (maxInboundMessageBodySize );
1596+ return result ;
1597+ }
1598+
1599+ protected AMQConnection createConnection (
1600+ ConnectionParams params , FrameHandler frameHandler , MetricsCollector metricsCollector ) {
1601+ return new AMQConnection (params , frameHandler , metricsCollector , observationCollector );
1602+ }
1603+
1604+ /**
1605+ * Create a new broker connection.
1606+ *
1607+ * <p>If <a href="https://www.rabbitmq.com/api-guide.html#recovery">automatic connection
1608+ * recovery</a> is enabled, the connection returned by this method will be {@link Recoverable}.
1609+ * Reconnection attempts will always use the address configured on {@link ConnectionFactory}.
1610+ *
1611+ * @return an interface to the connection
1612+ * @throws IOException if it encounters a problem
1613+ */
1614+ public Connection newConnection () throws IOException , TimeoutException {
1615+ return newConnection (
1616+ this .sharedExecutor , Collections .singletonList (new Address (getHost (), getPort ())));
1617+ }
1618+
1619+ /**
1620+ * Create a new broker connection.
1621+ *
1622+ * <p>If <a href="https://www.rabbitmq.com/api-guide.html#recovery">automatic connection
1623+ * recovery</a> is enabled, the connection returned by this method will be {@link Recoverable}.
1624+ * Reconnection attempts will always use the address configured on {@link ConnectionFactory}.
1625+ *
1626+ * @param connectionName client-provided connection name (an arbitrary string). Will be displayed
1627+ * in management UI if the server supports it.
1628+ * @return an interface to the connection
1629+ * @throws IOException if it encounters a problem
1630+ */
1631+ public Connection newConnection (String connectionName ) throws IOException , TimeoutException {
1632+ return newConnection (
1633+ this .sharedExecutor ,
1634+ Collections .singletonList (new Address (getHost (), getPort ())),
1635+ connectionName );
1636+ }
1637+
1638+ /**
1639+ * Create a new broker connection.
1640+ *
1641+ * <p>If <a href="https://www.rabbitmq.com/api-guide.html#recovery">automatic connection
1642+ * recovery</a> is enabled, the connection returned by this method will be {@link Recoverable}.
1643+ * Reconnection attempts will always use the address configured on {@link ConnectionFactory}.
1644+ *
1645+ * @param executor thread execution service for consumers on the connection
1646+ * @return an interface to the connection
1647+ * @throws IOException if it encounters a problem
1648+ */
1649+ public Connection newConnection (ExecutorService executor ) throws IOException , TimeoutException {
1650+ return newConnection (executor , Collections .singletonList (new Address (getHost (), getPort ())));
1651+ }
1652+
1653+ /**
1654+ * Create a new broker connection.
1655+ *
1656+ * <p>If <a href="https://www.rabbitmq.com/api-guide.html#recovery">automatic connection
1657+ * recovery</a> is enabled, the connection returned by this method will be {@link Recoverable}.
1658+ * Reconnection attempts will always use the address configured on {@link ConnectionFactory}.
1659+ *
1660+ * @param executor thread execution service for consumers on the connection
1661+ * @param connectionName client-provided connection name (an arbitrary string). Will be displayed
1662+ * in management UI if the server supports it.
1663+ * @return an interface to the connection
1664+ * @throws IOException if it encounters a problem
1665+ */
1666+ public Connection newConnection (ExecutorService executor , String connectionName )
1667+ throws IOException , TimeoutException {
1668+ return newConnection (
1669+ executor , Collections .singletonList (new Address (getHost (), getPort ())), connectionName );
1670+ }
1671+
1672+ protected AddressResolver createAddressResolver (List <Address > addresses ) {
1673+ if (addresses == null || addresses .isEmpty ()) {
1674+ throw new IllegalArgumentException ("Please provide at least one address to connect to" );
1675+ } else if (addresses .size () > 1 ) {
1676+ return new ListAddressResolver (addresses );
1677+ } else {
1678+ return new DnsRecordIpAddressResolver (addresses .get (0 ), isSSL ());
16791679 }
1680+ }
16801681
16811682 @ Override
16821683 public ConnectionFactory clone () {
0 commit comments