Deploy Your Model

In this tutorial, you’ll learn how to package your digital twin model, deploy it with the ScaleOut Digital Twins UI, and send it a message with the REST service.

Important

Before proceeding, make sure you’ve either built the digital twin model following the instructions in Build Your First Digital Twin Model, or downloaded the finished model files from this repository.

Package Your Model

Note: If you downloaded the model .zip file from the link above, you can skip this step.

In Visual Studio, right-click on the MyRealTimeTwin project and select “Publish…” The publishing window will allow you to select from several predefined targets (Windows vs. Linux). Click the Publish button.

Once publishing has completed, you can find a zip folder MyRealTimeTwin.zip in the folder path\to\your\model\MyFirstModel\MyRealTimeTwin\bin\PublishedZip

Alternatively, the DT tool can be used to package your project from the command line:

dt pack -r linux-x64

Log in to the Digital Twins UI

Navigate to the ScaleOut Digital Twins UI at https://localhost:5501. Click the Login button.

You can use the built-in account to log in:

  • user name: admin@streamserver.dt

  • password: Sc@le0ut

You also can create a new account by pressing the Log In button and clicking the Register as a new user link to create a user account. You should enter the email address you would like to use and a password. The password must be between 6 and 100 characters long, have at least one non-alphanumeric character, have at least one digit (‘0’-‘9’), and have at least one uppercase (‘A’-‘Z’).

Deploy Your Model

In the UI, navigate to Models and click Create Model.

Fill out the form:

  • For the model name, enter “MyRealTimeTwin”.

  • For the resource file, locate the zip file you generated earlier and upload it.

  • For the language, select the language you used to develop the model.

  • Ensure “Deploy when created” is checked.

  • Any other fields can be left blank.

Click Create Model to finish creating your model.

Once the model is successfully created, navigate back to the Models page and your model should appear in the table. You can click on the model name to view its details.

Note

The model doesn’t have any instances yet, but it will automatically create them when it starts receiving messages. Each message contains a unique digital twin instance ID. If the ID in the message doesn’t match an existing instance, the system will create a new instance with that ID.

Send a Test Message

Now we’ll send a message with the built-in REST service to simulate a message coming from a real-world device. In practice, real-world connected devices such as sensors can use the REST service the same way to send telemetry to digital twin instances.

Create an API key

We’ll first create an API key that allows us to connect to the REST service.

In the UI, navigate to the API Keys page.

Enter a name for your API key and click Generate API Key. Click Copy Key in the table to copy the key. We’ll use it in the next step.

Send a Message

Navigate to the Swagger page for the Messaging REST API: https://localhost:8801/swagger/index.html

Open the endpoint POST /Messages/{model}/{twinId} and click Try it out.

Fill out the parameters:

  • model: MyRealTimeTwin

  • twinId: 1

  • apiKey: the API key you generated in the last step

Note

Any alphanumeric string is a valid digital twin instance ID. When you create your own models, you can use whatever instance naming scheme you prefer.

For the request body, enter the following:

[{
    "StringPayload": "Hello World"
}]

Important

When sending messages through the messaging REST API, the request body must be enclosed in square brackets in order to be deserialized, even if you’re only sending one message.

Click the Execute button, and the request should return a 202 status.

Navigate back to the Models page in the UI and click on the model name to view its details. You should see a newly created instance and a message that reads “The real-time digital twin ‘1’ says ‘Hello World’”.

Congratulations! You have successfully deployed your first digital twin model. Continue to the next section to learn about the next steps you can take with ScaleOut Digital Twins.