Service-level configuration

Updated at:

This topic describes how to publish and reference SOFARPC services in a SOFABoot environment.

Publish a service

<bean id="helloSyncServiceImpl" class="com.alipay.sofa.rpc.samples.invoke.HelloSyncServiceImpl"/>
<sofa:service ref="helloSyncServiceImpl" interface="com.alipay.sofa.rpc.samples.invoke.HelloSyncService" unique-id="">
<sofa:binding.bolt>
<sofa:global-attrs registry="" serialize-type="" filter="" timeout="3000" thread-pool-ref=" "
warm-up-time="60000"
warm-up-weight="10" weight="100"/>
</sofa:binding.bolt>
<sofa:binding.rest>
</sofa:binding.rest>
</sofa:service>

Property descriptions:

Property

Default value

Description

id

Bean name

ID

class

-

The class.

ref

-

The service interface implementation class.

interface

-

The service interface, which is a unique identifier element.

unique-id

-

The service tag, which is a unique identifier element.

filter

-

The alias of the filter configuration.

registry

DSR

The server-side registry. To specify multiple registries, separate them with commas.

For more information about supported registries, see Registry routing.

timeout

3000

The server-side execution timeout period.

Unit: ms.

serialize-type

hessian2

The serialization protocol. Valid values: hessian2 and protobuf.

thread-pool-ref

-

A custom business thread pool. This must point to a com.alipay.sofa.rpc.core.context.UserThreadPool object.

weight

100

The static weight of the service. A larger value indicates a higher weight.

warm-up-weight

10

The warm-up weight of the service provider. When a client establishes a connection, this weight is used during the specified ramp-up period.

warm-up-time

0

The ramp-up period of the service provider. When a client establishes a connection, the warm-up weight is used during this period.

Unit: ms.

Reference service

<sofa:reference jvm-first="false" id="helloSyncServiceReference"
interface="com.alipay.sofa.rpc.samples.invoke.HelloSyncService" unique-id="">
<sofa:binding.bolt>
<sofa:global-attrs type="sync" timeout="3000" callback-ref="" callback-class="" address-wait-time="1000"
connect.num="1" check="false" connect.timeout="1000" filter="" generic-interface=""
idle.timeout="1000"
idle.timeout.read="1000" lazy="false" loadBalancer="" registry="" retries="1"
serialize-type=""/>
<sofa:route target-url="xxx:12200"/>
<sofa:method name="hello" callback-class="" callback-ref="" timeout="3000" type="sync"/>
</sofa:binding.bolt>
</sofa:reference>

Property descriptions:

Property

Default value

Description

id

Automatically generated

The ID.

jvm-first

true

Specifies whether to prioritize the use of the local JVM configuration. Valid values: true and false.

interface

-

The service interface, which is a unique identifier element.

You must set the actual interface class for both regular calls and return calls.

unique-id

-

The service tag, which is a unique identifier element.

type

sync

The invocation method. Valid values: sync, oneway, callback, and future.

filter

-

The alias of the filter configuration.

registry

DSR

The server-side registry. To specify multiple registries, separate them with commas.

For more information about supported registries, see Registry routing.

method

-

The method-level configuration. Properties configured for method have a higher priority than those in global-attrs. If this is not configured, the global configuration is used by default.

serialize-type

hessian2

The serialization protocol. Valid values: hessian2 and protobuf.

target-url

-

The endpoint in direct connection mode.

After you configure target-url, the software load balancing phase becomes invalid. For more information, see Direct connection invocation.

generic-interface

-

The generalization interface.

connect.timeout

1000

The connection timeout period for the consumer.

Unit: ms.

connect.num

-1

The number of connections for the consumer.

A value of -1 indicates that this property is not set. By default, one connection is established for each destination address.

idle.timeout

-1

The maximum idle time for the consumer.

A value of -1 indicates that the underlying default value is used. The underlying default value is 0, which means idle is never read. This configuration also specifies the heartbeat interval. When the request idle time exceeds the configured time, a heartbeat is sent to the service provider.

idle.timeout.read

-1

The maximum read idle time for the consumer.

A value of -1 indicates that the underlying default value is used. The underlying default value is 30. If idle.timeout > 0 and no request occurs within the idle.timeout + idle.timeout.read period, the connection is automatically disconnected.

loadBalancer

random

The load balancing algorithm.

lazy

false

Specifies whether to delay the establishment of a persistent connection. Valid values: true and false.

address-wait-time

0

The time to wait for the configuration center to push the address to the consumer when the reference is generated.

Unit: ms.

The maximum value is 30000 ms. If you specify a value greater than 30000, it is adjusted to 30000 ms.

timeout

3000

The invocation timeout period.

retries

0

The number of automatic retries at the framework level when a non-business exception occurs. The service provider must ensure the idempotence of the method.

callback-class

-

The callback class. For more information, see Invocation methods of the Bolt protocol.

This is available only for callback invocations.

callback-ref

-

The callback class. For more information, see Invocation methods of the Bolt protocol.

This is available only for callback invocations.

Configuration priority

You can set some SOFARPC configurations, such as the timeout property for invocation timeouts, on either the service provider or the service consumer side. The following list shows the configuration priority in descending order:

  1. Thread invocation level settings.

  2. Service consumer side.

    • Method-level settings.

    • Reference-level settings.

  3. Service provider side.

    • Method-level settings.

    • Service-level settings.