# Create message classes

Manufacturing Data Engine (MDE) lets you transform a series of source
messages into records of a specific type by means of
[parsing](https://docs.cloud.google.com/manufacturing-data-engine/docs/concepts/parser.md.txt).

Source message classes are configuration entities that represent the *source*
of the parsing operation, and describe a set of structurally and semantically
similar source messages.

![source-to-target](https://docs.cloud.google.com/static/manufacturing-data-engine/images/source-to-target.png)

Source message classes provide a predictable message schema to parsers so that
transformations, mappings, and data extraction can be performed on known fields.

## Source message classification

Each message class has an associated *message class expression* and a priority.
The priority of a message class is an integer from 0 to 65535 , inclusive. Lower
integers indicate higher priorities.

A source message is associated to a source message class when the first source
message class expression evaluates to `true` after the classes are sorted on
priority.

Source message class expressions are written in
[Spring Expression Language (SpEL)](https://docs.spring.io/spring-framework/docs/5.3.0/reference/html/core.html#expressions-language-ref).

![source-message-class](https://docs.cloud.google.com/static/manufacturing-data-engine/images/smc-illustration.png)

SpEL expressions can access
[source message attributes (Pub/Sub attributes)](https://docs.cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage.md.txt)
and data. The message attributes are exposed under the
`#root.headers` key, and data is exposed under the `#root.event` key.

The following are examples of SpEL expressions for a source message class:

    #root.event['MessageType'] != null && #root.event['MessageType'] matches 'Sensor.*'

    #root.headers['source'] != null && #root.headers['source'] == 'MCe'

### Naming restrictions for message classes

A message class name can contain the following:

- Letters (uppercase and lowercase), numbers, and the special characters `-` and `_`.
- Can be up to 255 characters long.

You can use the following regular expression for validation:
`^[a-z][a-z0-9\\-_]{1,255}$`

If you try to create an entity violating the naming restrictions you will get
a `400 error`.